Option Explicit ' OneXcel Studio | Table of contents with a hyperlink to every sheet ' Creates (or rebuilds) a "Contents" sheet at the front of the workbook. Private Const TOC_NAME As String = "Contents" ' name of the contents sheet Private Const SHOW_HIDDEN As Boolean = False ' True = list hidden sheets too Public Sub CreateTableOfContents() Dim wb As Workbook, toc As Worksheet, ws As Worksheet Dim r As Long, n As Long, target As String, lastRow As Long Set wb = ThisWorkbook Application.ScreenUpdating = False ' 1. Reuse the Contents sheet if it exists, otherwise add it at the front On Error Resume Next Set toc = wb.Worksheets(TOC_NAME) On Error GoTo 0 If toc Is Nothing Then Set toc = wb.Worksheets.Add(Before:=wb.Worksheets(1)) toc.Name = TOC_NAME Else toc.Move Before:=wb.Worksheets(1) toc.Cells.Clear End If toc.Range("A1").Value = "Contents" toc.Range("A1").Font.Size = 16 toc.Range("A1").Font.Bold = True toc.Range("A3:D3").Value = Array("No.", "Sheet", "Title (cell A1)", "Rows used") toc.Range("A3:D3").Font.Bold = True r = 3 ' 2. One row per sheet, with a HYPERLINK formula to cell A1 of that sheet For Each ws In wb.Worksheets If ws.Name <> TOC_NAME Then If ws.Visible = xlSheetVisible Or SHOW_HIDDEN Then r = r + 1: n = n + 1 toc.Cells(r, 1).Value = n ' quote the name so spaces and apostrophes work: #'Owner''s notes'!A1 target = "#'" & Replace(ws.Name, "'", "''") & "'!A1" toc.Cells(r, 2).Formula = "=HYPERLINK(""" & target & """,""" & _ Replace(ws.Name, """", """""") & """)" toc.Cells(r, 3).Value = CStr(ws.Range("A1").Value) lastRow = ws.UsedRange.Row + ws.UsedRange.Rows.Count - 1 If Application.WorksheetFunction.CountA(ws.Cells) = 0 Then lastRow = 0 toc.Cells(r, 4).Value = lastRow If ws.Visible <> xlSheetVisible Then _ toc.Cells(r, 3).Value = toc.Cells(r, 3).Value & " (hidden)" End If End If Next ws ' 3. Tidy up toc.Cells(r + 2, 1).Value = n & " sheets listed. Run the macro again after adding or renaming sheets." toc.Cells(r + 2, 1).Font.Italic = True toc.Columns("A:D").AutoFit toc.Activate toc.Range("B4").Select Application.ScreenUpdating = True End Sub