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.
以上是如何在Excel中創建動態目錄的詳細內容。更多資訊請關注PHP中文網其他相關文章!

鼠標是在PC上完成工作的重要組成部分。但是,當您陷入錯誤的鼠標時,您可能會遇到一些問題,包括無法右鍵單擊。但是好消息是,肯定有一些方法

保持乾淨有效的Windows體驗對於最佳性能至關重要。 以下是一些常見的陷阱: 1。超載啟動應用程序:太多的啟動應用程序大大減慢了啟動時間和整體系統的滲透

在當今的觸摸屏世界中,身體控制的令人滿意的觸覺反饋是一個可喜的變化。 這就是為什麼具有較大音量旋鈕的鍵盤令人驚訝地吸引人的原因。我最近親身經歷了這是一個啟示。 為了

Windows 11剪裁工具獲得了強大的新OCR功能:說再見到手動文本選擇! Windows 11的剪切工具剛剛獲得了重大升級,增加了光學角色識別(OCR)功能。這允許用戶從V中選擇文本

本指南說明瞭如何更改Windows 11和10中文件資源管理器的默認打開位置。默認的“ HOME”視圖雖然方便一些,但可能會損害隱私或工作流程效率。 本教程提供了三種方法

Acer最新遊戲筆記本電腦系列令人驚艷,但該公司還推出了一款台式電腦,這款電腦在Acer的產品線中位置尷尬,與其他小型台式電腦相比,它也有其自身的優缺點。 Acer今日在其廣受歡迎的Nitro遊戲系列中增加了四款新筆記本電腦和一款重新設計的緊湊型台式電腦。不過,讓我們先談談台式電腦,因為它最獨特。它的獨特之處在於它使用了筆記本電腦規格。 Nitro 20 N20-100採用AMD Ryzen AI 9 365處理器,或者也可以選擇Intel Core i5-13420H台式機處理器。顯卡最高可配備

限量運行遊戲正在發布限量版的《厄運II:它會運行版》盒裝,這是對持久的“可以運行厄運嗎?”的嬉戲點頭。模因。 此奢侈的集合包括前兩個厄運遊戲的重新製作版本,可玩AC

Nanoleaf的Pegboard Desk Dock:時尚且功能型的桌子組織者 厭倦了相同的舊充電設置? NanoLeaf的新Pegboard Desk Dock提供了一種時尚且功能性的替代方案。 這款多功能桌配件擁有32個全彩RGB


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

記事本++7.3.1
好用且免費的程式碼編輯器