• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Iterate adding hyperlink code

I have code that creates hyperlink to only one cell. I want it to iterate through all filled cells along column F or C or E.
Code:
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
 
Try this code
Code:
Sub insertVeryLongHyperlink()
    Dim curCell As Range
    Dim longHyperlink
    Dim textToDisplay1 As String
    Dim i As Long

    For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    Set curCell = Range("G" & i)
    longHyperlink = Range("E" & i)
    textToDisplay1 = Range("C" & i)

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

End Sub
 
Back
Top