Macro to go to cell

J

jeff

Hi,

Here's some code that can be used with either a button
and a listbox. Commandbutton1 uses value in B5. Listbox1
has it's list somewhere, and its linked cell as E1.
Make a selection and off you go

try it.
jeff
=====================================

Private Sub CommandButton1_Click()
Range("B5").Select
testme
End Sub

Sub testme()
With Selection(1)
If .Hyperlinks.Count > 0 Then
.Hyperlinks(1).Follow NewWindow:=True,
addhistory:=True
Else
If .Formula Like "=HYPERLINK(*" Then
ActiveWorkbook.FollowHyperlink .Value, _
NewWindow:=True, addhistory:=True
End If
End If
End With
End Sub

Private Sub ListBox1_Click()
Dim cc As Variant
Range("E1").Select
If Left(Selection, 5) = "http:" Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:=Selection
' "http://spt.schwab.com", TextToDisplay:="Schwab
Home"
Else
cc = Selection
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="", SubAddress:=cc
' "Sheet2!C5", TextToDisplay:="Sheet 2"
End If
testme
End Sub
 

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

Top