VBA code to rename hyperlink according to value in each row

leonc337

New Member
Joined
Feb 22, 2022
Messages
1
Platform
  1. Windows
Greetings all,

I'm relatively new to VBA and I would like some help on a problem I'm trying to solve for. I have two columns of data and both of them are text initially.
I first ran the VBA below to turn texts in the "Hyperlink" column into clickable links. However, I would also like them to be renamed to the corresponding friendly name using texts showed on the left column. Is there a VBA code that can make this work? If the 2 steps (turn text into hyperlink + rename) can be combined into one that's better. <*** I would only want VBA solution because some of the link exceed formula text limit so formula won't work>

Many Thanks!!!
1.png
2.png
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Alex Blakenburg

MrExcel MVP
Joined
Feb 23, 2021
Messages
5,034
Office Version
  1. 365
Platform
  1. Windows
Give this a try:-
VBA Code:
Sub CreateHyperlink()
    Dim rCell As Range

    For Each rCell In Range("B5:B" & Cells(Rows.Count, "B").End(xlUp).Row)
        ActiveSheet.Hyperlinks.Add Anchor:=rCell, Address:=rCell.Value, TextToDisplay:=rCell.Offset(, -1).Value
    Next rCell
End Sub
 

JohanGduToit

Board Regular
Joined
Nov 12, 2021
Messages
76
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
This does the trick for converting only cells in column I that contains a value:

VBA Code:
Dim rCell as Range
For Each rCell In .Application.Range("I2:I" & .Application.Cells(Rows.Count, "I").End(xlUp).Row)
            If IsEmpty(rCell.Value) = False Then
                .Application.ActiveSheet.Hyperlinks.Add Anchor:=rCell, Address:=rCell.Value, TextToDisplay:=rCell.Offset(, -3).Value
            End If
Next rCell
 

Forum statistics

Threads
1,175,753
Messages
5,899,280
Members
434,759
Latest member
carcharoth

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
Top