Quickly create links to sheets, tables, pivot tables and named ranges in a workbook
A week ago I posted Create links to all sheets in a workbook and today I want to show you how to create links to all:
- Worksheets
- Pivot tables
- Tables
- Named ranges
in a workbook.
How to use
- Select a cell
- Go to tab "Developer"
- Click "Macros" button
- Select CreateToC
- Click "Run" button
VBA code
Sub CreateToC()
Dim sh As Worksheet
Dim cell As Range
Dim pt As PivotTable
Dim tbl As ListObject
Dim nms As Name
ActiveCell.Value = "Table of Contents"
ActiveCell.Font.Bold = True
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = "Worksheets"
ActiveCell.Offset(1, 0).Select
For Each sh In ActiveWorkbook.Worksheets
If ActiveSheet.Name <> sh.Name Then
ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'" & sh.Name & "'" & "!A1", TextToDisplay:=sh.Name
ActiveCell.Offset(1, 0).Select
End If
Next sh
ActiveCell.Value = "Pivot tables"
ActiveCell.Offset(1, 0).Select
For Each sh In ActiveWorkbook.Worksheets
For Each pt In sh.PivotTables
ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'" & sh.Name & "'!" & pt.TableRange1.Address, TextToDisplay:=pt.Name
ActiveCell.Offset(1, 0).Select
Next pt
Next sh
ActiveCell.Value = "Tables"
ActiveCell.Offset(1, 0).Select
For Each sh In ActiveWorkbook.Worksheets
For Each tbl In sh.ListObjects
ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
tbl.Name, TextToDisplay:=sh.Name
ActiveCell.Offset(1, 0).Select
Next tbl
Next sh
ActiveCell.Value = "Named ranges"
ActiveCell.Offset(1, 0).Select
For Each nms In ActiveWorkbook.Names
ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
nms.Name, TextToDisplay:=nms.Name
ActiveCell.Offset(1, 0).Select
Next nms
ActiveSheet.Columns(ActiveCell.Column).AutoFit
End Sub
Download excel *.xlsm file
Quickly create links to sheets pivot tables tables and named ranges.xlsm
Related posts:
Create links to all sheets in a workbook
Consolidate sheets in excel, part 2
Consolidate sheets in excel (vba)
Quickly create new sheets (vba)
List all tables and corresponding headers in a workbook (vba)


















Sub Cmdty()
Dim PT As PivotTable
Dim PTcache As PivotCache
Dim pf As PivotField
Dim pi As PivotItem
On Error Resume Next
Sheets.Add
ActiveSheet.Name = "PVT"
Set PTcache = ActiveWorkbook.PivotCaches.Create(xlDatabase, Range("A5,DC6577"))
Set PT = ActiveSheet.PivotTables.Add(PTcache, Range("A1"), "Table")
With PT
.AddFields("GROUP").Orientation = xlRowField
.AddFields("QTY").Orientation = xlDataField
.AddFields("STD").Orientation = xlDataField
.AddFields("MR$").Orientation = xlDataField
.AddFields("FCST").Orientation = xlDataField
.AddFields("PPV").Orientation = xlDataField
End With
End Sub
actually I corrected the code:
...
Sheets("PVT").Select
Set PT = ActiveSheet.PivotTables.Add(PTcache, Range("A1"), "Table")
...
Still to no avail... if you will notice my data range is very long... It's very frustrating I cannot work it out on myself. could you help out on this? Thanks in advance