activate hyperlinks VBA

Leske

Active Member
Joined
Aug 26, 2008
Messages
297
Hello

I have a link in excel but it not activate.

So for the moment i press F2 and hit enter that way the hyperlinks works.

Now i want to do this with a Macro:

Code:
Dim LastRow As Long, i As Long
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
'
If Cells(i, 2).Value <> "" Then
 
    [COLOR=#ff0000]ActiveCell.Hyperlinks
[/COLOR]    
   
End If
Next i
End Sub

But don't know the code for just activate it so if anyone can help me with the red part that would be great.

Kind regards,

Lesly
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Does this work for you?

Code:
Sub Test()
    Dim LastRow As Long, i As Long
    LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        With Cells(i, 2)
            If .Value <> "" Then
                ActiveSheet.Hyperlinks.Add Anchor:=.Cells(1, 1), Address:=.Value
            End If
        End With
    Next i
End Sub
 
Upvote 0
Yes it works but i have a few questions why do you use with cells(i,2)?

And how does the code of hyperlinks work? what does Anchor means and why do you use .cells(1,1)

Kind regards,

thx for your help
 
Upvote 0
I used a With ... End With construct to avoid repeating the reference. Without it the code would be:

Rich (BB code):
Sub Test()
    Dim LastRow As Long, i As Long
    LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        If Cells(i, 2).Value <> "" Then
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 2), Address:=Cells(i, 2).Value
        End If
    Next i
End Sub

Anchor is the cell that contains the Hyperlink.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top