Search code examples
excelvbahyperlinkcell

How to get cell location of H and add to hyperlink


I am setting up hyperlinks in a range to go to cells in a table

Everything works apart from p. It is supposed to get the cell location and then insert it in the address.

Dim t1 As ListObject
    Set t1 = Range("Testtbl").ListObject
    Dim i As Integer
    Dim j As Integer
    Dim p As String

    For Each cell In rng
    For i = 1 To t1.ListRows.Count
        If t1.ListColumns("UnLockedField").DataBodyRange(i) = "H" Then

        p = Range(t1.ListColumns("UnLockedField").DataBodyRange(i))


        With cell
         .Hyperlinks.Add Anchor:=cell, _
         Address:=p
        End With


        GoTo NEXTONE

    End If

    Next i

NEXTONE:
Next cell
End If

I am hoping that p would get the cell loaction and then insert that cell into the address.


Solution

  • You do not need the Range object and cannot use it (as you are doing) to achieve what you want. It should be:
    p = t1.ListColumns("UnLockedField").DataBodyRange.Cells(i).Address