Hyperlinks VBA

mlo356

Board Regular
Joined
Aug 20, 2015
Messages
51
Hi All,

I am struggling with getting hyperlinks to work in VBA using vlookup. Any help would be appreciated

I have 2 sheets.

Sheet 1 has a salesman # in cell A1. To keep it simple, the salesman # is 101. no hyperlink exist yet.

Sheet 2 has a list of salesman #s in column A and salesman #101 is in this list. Columns B-E has info related to the salesman

I would like to lookup the salesman # in sheet1.A1 (which is 101) on sheet2.A:A.

If it finds the salesman #, Convert text in sheet1.A1 into a link. the link takes me to the matching row on sheet2.

If not found, do not convert to link

I was going to upload code but I failed miserably at it and don't think would be useful.

Thanks in advance!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This creates links for all

Code:
Sub findsalesman()

Dim rownum As Long
Dim rownum1 As Long
Dim salesman As String
Dim salesmanfound As String

Sheets("Sheet2").select


rownum1 = 1
rownum = 1


Do Until Sheets("Sheet1").Cells(rownum1, 1).Value = ""


salesman = Sheets("Sheet1").Cells(rownum1, 1).Value




    Do Until Sheets("Sheet2").Cells(rownum, 1).Value = ""


        If Sheets("Sheet2").Cells(rownum, 1).Value = salesman Then


        salesmanfound = Sheets("Sheet2").Cells(rownum, 1).Address
        
        GoTo nextsalesman


        End If


        rownum = rownum + 1


    Loop


nextsalesman:


Sheets("Sheet1").Select
Sheets("Sheet1").Cells(rownum1, 1).Select
Sheets("Sheet1").Cells(rownum1, 1).Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="Sheet2!" & salesmanfound


rownum = 1


rownum1 = rownum1 + 1


Loop


End Sub
 
Last edited:
Upvote 0
This creates links for all

Code:
Sub findsalesman()

Dim rownum As Long
Dim rownum1 As Long
Dim salesman As String
Dim salesmanfound As String

Sheets("Sheet2").select


rownum1 = 1
rownum = 1


Do Until Sheets("Sheet1").Cells(rownum1, 1).Value = ""


salesman = Sheets("Sheet1").Cells(rownum1, 1).Value




    Do Until Sheets("Sheet2").Cells(rownum, 1).Value = ""


        If Sheets("Sheet2").Cells(rownum, 1).Value = salesman Then


        salesmanfound = Sheets("Sheet2").Cells(rownum, 1).Address
        
        GoTo nextsalesman


        End If


        rownum = rownum + 1


    Loop


nextsalesman:


Sheets("Sheet1").Select
Sheets("Sheet1").Cells(rownum1, 1).Select
Sheets("Sheet1").Cells(rownum1, 1).Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="Sheet2!" & salesmanfound


rownum = 1


rownum1 = rownum1 + 1


Loop


End Sub


Thank You so much mrshl9898!! This worked great. Didn't think to use a loop.
 
Upvote 0

Forum statistics

Threads
1,223,339
Messages
6,171,532
Members
452,409
Latest member
brychu

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