listbox

G

Greg B

I have a listbox which I am listing cells a1:a1000 on a worksheet called
"homes". I would like the ability to have the user highlight the item in
the list box and execute a code that will go to that cell.

Is this possible

Thanks

Greg
 
T

Tom Ogilvy

Assuming a listbox from the control toolbox toolbar, you can use the click
event:

Private Sub ListBox1_Click()
If listbox1.ListIndex <> -1 then
Range(Listbox1.Value).Select
End If
End Sub
 
G

Greg B

Thanks Tom
Tom Ogilvy said:
Assuming a listbox from the control toolbox toolbar, you can use the click
event:

Private Sub ListBox1_Click()
If listbox1.ListIndex <> -1 then
Range(Listbox1.Value).Select
End If
End Sub
 
G

Greg B

Just a little further with this one. Am I able to execute a hyperlink using
this method? I have tried it but it comes with the runtime error.

Thanks
Greg
 
T

Tom Ogilvy

What do you mean by execute a hyperlink. You asked about selecting a cell.

You would have to describe what you want to do if you hope to get an answer
that is relevant. Just using code to select a cell containing a hyperlink
doesn't execute the hyperlink - just like you can select a cell manually and
not fire the hyperlink.

Private Sub ListBox1_Click()
Dim rng as Range
If listbox1.ListIndex <> -1 then
set rng = Range(Listbox1.Value)
if rng.hyperlinks.count > 0 then
rng.select
rng.parent.parent.FollowHyperlink rng.hyperlinks(1).Address, _
rng.Hyperlinks(1).SubAddress, True
end if
End If
End Sub

might be close - it depends on what you have actually populated the Listbox
with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Excel Need Countifs Formula Help 0
Access Cannot select items in listbox 1
Conditional Formatting, contain SPACE 2
Conditional Formating, contain space 1
Listbox Problem 5
Listbox Query Again 1
Listbox 4
ListBox Click Event 6

Top