A table of contents is a total game-changer when working with large files – it keeps everything organized and easy to navigate. Unfortunately, unlike Word, Microsoft Excel doesn’t have a simple “Table of Contents” button that adds this handy feature and updates it automatically. No, you’ll have to roll up your sleeves and create a dynamic table of contents yourself. This table will automatically update and contain clickable links, allowing you to add and remove sheets – as well as jump between them – with ease. This guide has all the info you need to create a dynamic table of contents in Excel.
How to Create a Dynamic Table of Contents in Excel
Technically, there are three ways to create a dynamic table of contents (TOC) in Excel. However, only one of them guarantees a fully automated TOC, and that’s Visual Basic for Applications or VBA for short – Microsoft’s native programming language. The other two – traditional formulas and Power Query – will give you a semi-dynamic table of contents in Excel – one that either doesn’t include clickable links or doesn’t update automatically. Since we’re after a fully dynamic Excel table of contents, we’ll use VBA.
If you aren’t particularly VBA-savvy; don’t worry – you just need to follow a few steps. But first – let’s create our table of contents.
Step 1: Click on the “Insert Worksheet” button next to your sheets at the bottom.
Step 2: Name the sheet “Table of Contents.”
Step 3: Drag the sheet to the first position for better navigation.
Step 4: Enter the names of your sheets in Column A of the “Table of Contents” sheet.
And voilà – you’ve got your table of contents. You can play with the aesthetics of this TOC later – now, we need to make it dynamic. To do so, we’ll need the help of the VBA Editor – a built-in Excel tool that lets you write and run custom codes.
Step 1: Press “Alt + F11” to open the VBA Editor.
Step 2: Go to the “Insert” tab at the top.
Step 3: Select “Module” from the dropdown menu.
Step 4: Copy and paste the following VBA code:
Sub CreateTOC()
Dim ws As Worksheet
Dim toc As Worksheet
Dim i As Integer
‘ Check if TOC sheet already exists, delete if it does
On Error Resume Next
Set toc = ThisWorkbook.Sheets(“Table of Contents”)
On Error GoTo 0
If Not toc Is Nothing Then Application.DisplayAlerts = False: toc.Delete: Application.DisplayAlerts = True
‘ Create new TOC sheet
Set toc = ThisWorkbook.Sheets.Add(Before:=ThisWorkbook.Sheets(1))
toc.Name = “Table of Contents”
‘ Set up TOC header
toc.Cells(1, 1).Value = “Table of Contents”
toc.Cells(1, 1).Font.Bold = True
toc.Cells(1, 1).Font.Size = 14
‘ Loop through all sheets and add hyperlinks
i = 2
For Each ws In ThisWorkbook.Sheets
If ws.Name “Table of Contents” Then
toc.Hyperlinks.Add Anchor:=toc.Cells(i, 1), _
Address:=””, _
SubAddress:=”‘” & ws.Name & “‘!A1”, _
TextToDisplay:=ws.Name
i = i + 1
End If
Next ws
‘ Adjust column width
toc.Columns(“A”).AutoFit
End Sub
Step 5: Hit “F5” to run the code.
Step 6: Exit the VBA Editor.
You’ll notice your Excel table of contents is now clickable.
To automatically update your table of contents after changes, you just need to repeat Steps 1 to 6. This will add any new sheets to the list or remove the ones you deleted.
The above is the detailed content of How to Create a Dynamic Table of Contents in Excel. For more information, please follow other related articles on the PHP Chinese website!

This guide provides multiple ways to clear your Windows 11 clipboard, ensuring your copied data remains private. Your clipboard stores various items, including text, images, and videos. Let's explore several methods to erase its contents. Method 1:

Logitech G515 Lightspeed TKL Mechanical Gaming Keyboard Review The Logitech G515 Lightspeed TKL uses low profile keys and feels very similar to the Apple Magic Keyboard, but has an additional mechanical switch, which is slim overall and has a rechargeable battery. Amazon Link This keyboard is perfect for users who both work and games. Amazon currently sells for $119.99, down from its original price of $159.99, only once before it reached this price. G515 Lightspeed TKL is slim in size, 14.49 inches long and 5.91 inches wide,

Many users with powerful desktops were initially blocked from upgrading to Windows 11 due to a simple BIOS setting being disabled by default: TPM 2.0. This guide explains how to enable it. Checking for TPM Compatibility Windows has a built-in tool t

Quickly Access Your Favorite Websites: Two Methods for Adding Websites to Your Desktop Tired of hunting through bookmarks? Windows offers easy ways to add frequently visited websites directly to your desktop for instant access. This guide details tw

Windows 11's Run dialog box (Run) provides a convenient way to quickly access various system features and installed applications. The way to start this dialog is simple, just use keyboard shortcuts or select menu items. This article will describe several ways to start this utility. Use keyboard shortcuts to open the run dialog The quickest way to start a Run dialog on Windows 11 is to use keyboard shortcuts. This method opens the dialog box instantly. To do this, press the Windows R key on the keyboard. No matter where you are currently on your computer, Windows 11 will immediately open the Run dialog box. You can then enter the name of the utility you want to start.

Samsung Odyssey G7 (G70D) 32-inch Esports Monitor Special Offer! Original price is $800, current price is only $530, saving $270! This Odyssey G7 sports monitor has 4K resolution, IPS panel, 144Hz refresh rate, AMD FreeSync Premium support, and smart Tizen capabilities. Samsung's official website priced at $530 If you need a monitor that supports high refresh rate gaming, this Samsung 32-inch Odyssey G7 monitor is ideal for you. Currently on sale, priced at $530, $270 less than the original price, and comes with 4K resolution, IPS panel and smart software capabilities. 32-inch Odyss

Maintaining a Windows computer requires regular upkeep to ensure smooth operation and prevent performance issues, security risks, and unnoticed hardware problems. Here's a routine maintenance checklist to keep your computer running smoothly: 1. Run

The mouse is a vital component to getting work done on your PC. But when you’re stuck with a faulty mouse, you can run into a few problems including the inability to right-click. But the good news is that there are definitely ways t


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools