Trying to get URLs from another sheet using VLOOKUP in VBA

dagda13

Board Regular
Joined
May 18, 2019
Messages
52
Hi,

So I have a list of IDs in Sheet1. I am trying to replace them with hyperlinks using the below but I cannot seem to get VLOOKUP to work properly in VBA. I've tried to replace the "URL" string with a VLOOKUP to get the URLs that are on Sheet2, but everything I've tried has resulted in errors. Is there a way to get the Address with a simple VLOOKUP in the loop belew? Any help appreciated!

VBA Code:
Sub GetHyperlink()
   For Each xCell In Range("A:A")
      If xCell.Value <> "" Then
        ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:="URL", TextToDisplay:=xCell.Value
      End If
   Next xCell
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How are the URL stored on sheet2?? are they hyperlinks on sheet 2 or stored as text in cells , it makes a huge difference to the code you need depending on the answer. Also how are you going to identify which hyperlink you want i.e which column on sheet 1 matches which column on sheet2 , Which column on sheet 2 are the hyperlinks in??
 
Upvote 0
Hi offthelip,

Sorry, my bad that I was unclear. The below is more accurate code:

VBA Code:
Sub GetHyperlink()
     For Each xCell In Range("A:A")
          If xCell.Value <> "" Then
               ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:="IFNA(VLOOKUP(E" & ActiveCell.Row & ",Hidden!A:O,15,0),0)", TextToDisplay:=xCell.Value
          End If
     Next xCell
End Sub

The "Hidden" tab contains a column of ID's (column A) and corresponding URLs (column O).

Column E in "Sheet1" is a Vlookup against column A in "Hidden".
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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