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 - 适用于 Windows 的极简 GNU
这个项目正在迁移到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应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

记事本++7.3.1
好用且免费的代码编辑器