1

table_snpshotI have code that creates hyperlink in one cell. I want it to iterate through all filled cells along column F or C or E.

Sub insertVeryLongHyperlink()

Dim curCell As Range
Dim longHyperlink, TextToDisplay1 As String

Set curCell = Range("G1")  ' or use any cell-reference
longHyperlink = [E1]
TextToDisplay1 = [C1]

curCell.Hyperlinks.Add Anchor:=curCell, _
                Address:=longHyperlink, _
                SubAddress:="", _
                ScreenTip:=" - Click here to follow the hyperlink", _
                TextToDisplay:=TextToDisplay1

End Sub
3
  • Do you mean the hyperlink is in column E and the textToDisplay is in column C and you want to iterate over the columns and add a hyperlink to cells in column G? Commented Mar 14, 2017 at 12:59
  • Yes, you are right. I want to create hyperlinks till last row in table. Please find snapshot in main post. Commented Mar 14, 2017 at 13:10
  • Enclose your code in For...Loop and iterate over all rows. Commented Mar 14, 2017 at 13:13

1 Answer 1

2

This produces hyperlinks in column G.

Sub InsertVeryLongHyperlink()
    Dim cl As Range

    For Each cl In Range("G1:G" & Range("G1").End(xlDown).Row)
        cl.Hyperlinks.Add Anchor:=cl, Address:=cl.Offset(0, -2).Text, TextToDisplay:=cl.Offset(0, -4).Text, ScreenTip:=" - Click here to follow the hyperlink"
    Next cl
End Sub
  • cl.Offset(0, -2).Text is column E
  • cl.Offset(0, -4).Text is column C
Sign up to request clarification or add additional context in comments.

2 Comments

Great but need to change till last row. Right now range is fixed, can you help me to make range variable according to total row count?
Thanks, it's working great, just made one correction ("F1") instead of ("G1").

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.