Creating dynamic Hyper Link

dgkindy

New Member
Joined
Sep 9, 2009
Messages
9
I am trying to dynamically create a hyperlink based off a list of street names.

The problem occurs when I try to add the hyperlink to the spreadsheet.

I get the following error message

run time error 5

Invalid procedure or call argument

Code:
Sub Hyper()    
    Dim x As Integer
    x = 2
    Sheets("Streets").Select
    Do While Cells(x, 2) <> ""
        Cells(x, 2).Select
        Hyperaddress = "http://www.canada411.ca/search/ad/1/-/cZQQstZ" & Cells(x, 2) & "QQciZ" & Cells(1, 2) & "QQpvZONQQpcZ/?pgLen=10000"
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=Hyperaddress, TextToDisplay:=Cells(x, 2)
        x = x + 1
    Loop
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
At first glance try naming selection
linker = Cells(x, 2).Select

then use the name in the hyperlink part
Hyperaddress = "http://www.canada411.ca/search/ad/1/-/cZQQstZ" & Cells(x, 2) & "QQciZ" & Cells(1, 2) & "QQpvZONQQpcZ/?pgLen=10000"
ActiveSheet.Hyperlinks.Add Anchor:=linker, Address:=Hyperaddress, TextToDisplay:=Cells(x, 2)
x = x + 1
 
Upvote 0
Still no joy. I don't think the DIM would be the problem as VBA is pretty flexible in that you don't have you declare a lot of the basic variable to get the code to work.
Code:
Sub Hyper()    Dim x As Integer
    Dim linker As String
    x = 2
    Sheets("Streets").Select
    Do While Cells(x, 2) <> ""
        linker = "Cells(x, 2).Select"
        Hyperaddress = "http://www.canada411.ca/search/ad/1/-/cZQQstZ" & Cells(x, 2) & "QQciZ" & Cells(1, 2) & "QQpvZONQQpcZ/?pgLen=10000"
        ActiveSheet.Hyperlinks.Add Anchor:=linker, Address:=Hyperaddress, TextToDisplay:=Cells(x, 2)
        x = x + 1
    Loop
End Sub
 
Upvote 0
So the problem ended up being the Display name. You were close Roderick. Working code shown below,

Code:
Sub Hyper()    Dim x As Integer
    x = 2
    Sheets("Streets").Select
    Do While Cells(x, 2) <> ""
        Cells(x, 2).Select
        Display = Cells(x, 2)
        Hyperaddress = "http://www.canada411.ca/search/ad/1/-/cZQQstZ" & Cells(x, 2) & "QQciZ" & Cells(1, 2) & "QQpvZONQQpcZ/?pgLen=10000"
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=Hyperaddress, TextToDisplay:=Display
        x = x + 1
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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