I have an excel spreadheet that looks like this:
Input:
Link Name Hyperlink Other Data
Group 1 google.de/1 1
Group 1 google.de/2 2
Group 2 google.de/3 3
Group 2 google.de/4 4
Group 3 google.de/5 5
I need a VBA sub that assigns all strings in Link Name
as the name to the link in Hyperlink
:
Desired output:
Link Name Hyperlink Other Data
Group 1 Group 1 1 # Hyperlink: Underlined, blue
Group 1 Group 1 2 # Hyperlink: Underlined, blue
Group 2 Group 2 3 # Hyperlink: Underlined, blue
Group 2 Group 2 4 # Hyperlink: Underlined, blue
Group 3 Group 3 5 # Hyperlink: Underlined, blue
The Hyperlink
should now be clickable and labeled as defined in Link Name
. My current approach doesn't seem to loop through the Link Name
Column:
Current approach:
Sub rename_links()
For Each h In ActiveSheet.Hyperlinks // Select hyperlink
h.TextToDisplay = _
Replace(h.TextToDisplay, h.TextToDisplay, ActiveCell.Offset(0, -1).Value)
Next
End Sub
Current output:
Link Name Hyperlink Other Data
Group 1 Link Name 1
Group 1 Link Name 2
Group 2 Link Name 3
Group 2 Link Name 4
Group 3 Link Name 5
I blieve that this is due to ActiveCell.Offset(0, -1).Value
not being affected by Next
.
How to assign a string in column 1 as name to a hyperlink in column 2 across all rows in excel VBA?