Do you need to organize all the worksheets in your Excel workbook? Are you wondering how to create a table of contents in Excel? This Excel tutorial will explain the easiest ways to create an Excel table of contents with automation.
A table of contents helps you to navigate the document when it’s too large to remember all the sections. The same can also happen with an Excel workbook. This especially happens when the Excel file contains hundreds of worksheets. These worksheets can contain PivotTables, charts, graphs, dashboards, data-entry sheets, and so on.
Instead of remembering the workbook or writing down the important worksheet names on a sticky note, you can always create a table of contents in Excel. Unfortunately, there are no built-in functions or features in Excel that let you create a table of content in a single click like Microsoft Word.
Therefore, follow along with the methods mentioned below to create your table of contents in Excel without asking for help.
This method will utilize a formula containing a named range element. This is a semi-automatic method since you must perform a few manual tasks as well to create the table of contents for the first time.
=GET.WORKBOOK(1)&REPT(NOW(),)
=IF(ROW(A1)>SHEETS(),REPT(NOW(),),SUBSTITUTE(HYPERLINK("#'"&TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(INDEX(Worksheets,ROW(A1))," ",CHAR(255)),"]",REPT(" ",32)),32))&"'!A1",TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(INDEX(Worksheets,ROW(A1))," ",CHAR(255)),"]",REPT(" ",32)),32))),CHAR(255)," "))
To complete the TOC, follow these steps:
To go back to the TOC tab, simply click the worksheet name at the bottom of the Excel application. Alternatively, you can add the link to TOC in all the worksheets. To do this, either copy cell A1 from the TOC tab to all the worksheets in the workbook or use the following Excel VBA script:
Sub CopyFormulaToAllWorksheetsWithNewRowAtTop() Dim SourceSheet As Worksheet Dim DestSheet As Worksheet Dim SourceCell As Range Dim DestCell As Range Dim FirstRow As Long Dim ws As Worksheet Set SourceSheet = ThisWorkbook.Worksheets(1) Set SourceCell = SourceSheet.Range("A1") For Each ws In ThisWorkbook.Worksheets If ws.Name <> SourceSheet.Name Then Set DestSheet = ws Set DestCell = DestSheet.Range(SourceCell.Address) If DestCell.Value <> "" Then FirstRow = DestSheet.Cells(DestSheet.Rows.Count, "A").End(xlUp).Row DestSheet.Rows(FirstRow).EntireRow.Insert End If DestCell.Formula = SourceCell.Formula End If Next ws End Sub
Refer to the Excel VBA section below to learn how to use the above VBA script in your Excel workbook.
Here are the conditions to use the above method:
You can use the Power Query tool to create a list of all worksheets in the workbook. Then, apply the HYPERLINK function to create an Excel table of contents quickly.
So, if you’re accessing a large workbook using Power Query and it doesn’t have any table of contents tab, you can add that too to organize the workbook.
=HYPERLINK("#Sheet1!A1","Data1")
You can also use the following VBA script to add an Excel table of contents to any workbook that has many tabs, tables, PivotTables, etc.
Sub TOC() Dim TOCSheet As Worksheet Dim ws As Worksheet Dim rowNum As Long Set TOCSheet = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) TOCSheet.Name = "Table of Contents" TOCSheet.Cells(1, 1).Value = "Contents" TOCSheet.Cells(1, 2).Value = "Details" rowNum = 2 For Each ws In ThisWorkbook.Worksheets If ws.Name <> TOCSheet.Name Then TOCSheet.Cells(rowNum, 1).Value = ws.Name TOCSheet.Cells(rowNum, 2).Value = "Worksheet # " & ws.Index & " printable pages " & GetPrintablePageCount(ws) TOCSheet.Hyperlinks.Add _ Anchor:=TOCSheet.Cells(rowNum, 1), _ Address:="", _ SubAddress:=ws.Name & "!A1", _ TextToDisplay:=ws.Name rowNum = rowNum + 1 End If Next ws End Sub Function GetPrintablePageCount(ws As Worksheet) As Long Dim pageCount As Long pageCount = ws.PageSetup.Pages.Count GetPrintablePageCount = pageCount End Function
You might want to format the newly-created Table of Contents worksheet so that it becomes readable and presentable.
On Excel for the web or Excel for Microsoft 365 desktop applications, you can use the Office Scripts scripting tool to create automated Excel functions, like making an Excel table of contents worksheet. Find below the steps you must follow:
function main(workbook: ExcelScript.Workbook) < // Create a new worksheet called "TOC". let sheetNamesSheet = workbook.addWorksheet("TOC"); // Get the collection of worksheets in the workbook. let worksheets = workbook.getWorksheets(); // Create a string that will contain the list of sheet names. let sheetNames = ""; // Iterate over the worksheets and add their names to the string. for (let worksheet of worksheets) < sheetNames += worksheet.getName() + "\n"; >// Set the value of each cell in the "SheetNames" sheet to a sheet name. for (let i = 1; i >
Office Scripts will automatically create a new worksheet named TOC and list all the existing worksheets in the workbook in the order they appear.
function main(workbook: ExcelScript.Workbook) < let selectedSheet = workbook.getActiveWorksheet(); // Set range A1 on selectedSheet selectedSheet.getRange("A1").setValue("TOC"); // Reorder selectedSheet selectedSheet.setPosition(0); // Set range B2 on selectedSheet selectedSheet.getRange("B2").setFormulaLocal("=HYPERLINK(\"#Sheet1!A1\",\"Data 1\")"); // Paste to range B3:B6 on selectedSheet from range B2 on selectedSheet selectedSheet.getRange("B3:B6").copyFrom(selectedSheet.getRange("B2"), ExcelScript.RangeCopyType.all, false, false); // Set range B3:B6 on selectedSheet selectedSheet.getRange("B3:B6").setFormulasLocal([["=HYPERLINK(\"#Sheet3!A1\",\"Data 3\")"],["=HYPERLINK(\"#Sheet4!A1\",\"Data 4\")"],["=HYPERLINK(\"#PivotTable!A1\",\"PivotTable\")"],["=HYPERLINK(\"#Table!A1\",\"Table\")"]]); // Auto fit the columns of range B:B on selectedSheet selectedSheet.getRange("B:B").getFormat().autofitColumns(); >
If the TOC tab on your end is exactly the same as the example in this tutorial, the script will create a table of contents with redirect links.
Suppose your workbook is slightly different, then modify these code elements:
So far, you learned four different methods to create an Excel table of contents. Also, these methods come with different levels of automation. Depending on the number of components in your Excel workbook, like the count of worksheets, charts, PivotTables, etc., you must choose the most appropriate method.
When the workbook is comparatively smaller, like only a few worksheets, charts, tables, etc., you can rely on the custom function.
If the workbook is pretty large, try the Excel VBA method. If you need to create an Excel table of contents in Excel for the web app automatically, try the Office Scripts method. You can also try the Power Query method.
Once you’ve tried the above methods, comment below to tell us which method you liked the most.
I'm a freelance writer at HowToExcel.org. After completing my MS in Science, I joined reputed IT consultancy companies to acquire hands-on knowledge of data analysis and data visualization techniques as a business analyst. Now, I'm a professional freelance content writer for everything Excel and its advanced support tools, like Power Pivot, Power Query, Office Scripts, and Excel VBA. I published many tutorials and how-to articles on Excel for sites like MakeUseOf, AddictiveTips, OnSheets, Technipages, and AppleToolBox. In weekends, I perform in-depth web search to learn the latest tricks and tips of Excel so I can write on these in the weekdays!
Subscribe for awesome Microsoft Excel videos 😃
👉 Find out more about our Advanced Formulas course!