Forum Discussion

Cesarhamed's avatar
Cesarhamed
Copper Contributor
Dec 20, 2021

How to create multiple hyperlink

Ihave a set of tables under each other in one sheet and i want to create an index page with a hyperlink for each table. The link will take me to the beginning of each table, is it possible to do it in excel

1 Reply

  • Cesarhamed 

    Run this macro while the sheet with the tables is the active sheet:

    Sub CreateTOC()
        Dim wshS As Worksheet
        Dim wshT As Worksheet
        Dim tbl As ListObject
        Dim t As Long
        Application.ScreenUpdating = False
        Set wshS = ActiveSheet
        Set wshT = Worksheets.Add(After:=wshS)
        For Each tbl In wshS.ListObjects
            t = t + 1
            wshT.Hyperlinks.Add Anchor:=wshT.Range("A" & t), Address:="", _
                SubAddress:="'" & wshS.Name & "'!" & tbl.Range(1, 1).Address, _
                TextToDisplay:=tbl.Name
        Next tbl
        Application.ScreenUpdating = True
    End Sub

Resources