This article was co-authored by wikiHow staff writer, Megaera Lorenz, PhD. Megaera Lorenz is an Egyptologist and Writer with over 20 years of experience in public education. In 2017, she graduated with her PhD in Egyptology from The University of Chicago, where she served for several years as a content advisor and program facilitator for the Oriental Institute Museum’s Public Education office. She has also developed and taught Egyptology courses at The University of Chicago and Loyola University Chicago.
This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 152,304 times.
Learn more...
If your Excel workbook contains numerous worksheets, you can add a table of contents that indexes all of your sheets with clickable hyperlinks. This tutorial will teach you how to make an index of sheet names in your Excel workbook using a script you can copy and paste in a few easy steps, and how to add helpful "back to index" buttons to each sheet to improve navigation. We’ll also explain the basics of using the INDEX function.
Making a Simple Index in Excel
- You can index your workbook with a hyperlinked table of contents by running a script in the Code Editor.
- Add linked buttons back to the Table of Contents to make large workbooks easier to navigate.
- Use the INDEX function to retrieve data from a specific location in your sheet, or to perform calculations using a specified range.
Steps
Making the Index
-
1Click Automate at the top of your workbook. This method allows you to run a quick script that will generate a table of contents for your workbook. Each entry in the TOC will link to the corresponding sheet in the workbook. To get started, open your workbook and click the Automate tab at the top of the screen.[1]
-
2Select New Script. You’ll see this option on the left side of the ribbon menu. A small menu will open.Advertisement
-
3Click Create in Code Editor. The Code Editor panel will open on the right side of your workbook.
- If you’ve never used the Code Editor before, you might need to click through a couple of informational messages.
- You’ll see an example script in the window when you first open it.
-
4Paste the script below into the Code Editor window. If there’s an example script in the Code Editor window, select it all and delete it. Paste the following code in its place:
function main(workbook: ExcelScript.Workbook) { // Insert a new worksheet at the beginning of the workbook. let tocSheet = workbook.addWorksheet(); tocSheet.setPosition(0); tocSheet.setName("Table of Contents"); // Give the worksheet a title in the sheet. tocSheet.getRange("A1").setValue("Table of Contents"); tocSheet.getRange("A1").getFormat().getFont().setBold(true); // Create the table of contents headers. let tocRange = tocSheet.getRange("A2:B2") tocRange.setValues([["#", "Name"]]); // Get the range for the table of contents entries. let worksheets = workbook.getWorksheets(); tocRange = tocRange.getResizedRange(worksheets.length, 0); // Loop through all worksheets in the workbook, except the first one. for (let i = 1; i < worksheets.length; i++) { // Create a row for each worksheet with its index and linked name. tocRange.getCell(i, 0).setValue(i); tocRange.getCell(i, 1).setHyperlink({ textToDisplay: worksheets[i].getName(), documentReference: `'${worksheets[i].getName()}'!A1` }); }; // Activate the table of contents worksheet. tocSheet.activate(); }
-
5Click Run. You’ll see this green button at the top of the Code Editor panel. Click it and wait for the script to run. When it’s done, you should see a message that says “The script ran successfully.”
-
6Use the new index sheet to navigate your workbook. As soon as the script runs, a new sheet will appear at the front of your workbook called “Table of Contents.” Click a link in the Name column to go to the corresponding sheet.
- If you want to make it easier to get back to the Table of Contents from any sheet in the workbook, you can add an Index link to the other sheets.
Creating Hyperlinks Back to the Index
-
Click your index or table of contents sheet. If you have a lot of pages in your workbook, it'll be helpful to readers to add quick "Back to Index" or "Back to Table of Contents" links to each sheet so they don't have to scroll through lots of worksheet tabs after clicking to that page. Start by opening your index (or Table of Contents) sheet.
-
Name the index. To do this, just click the field directly above cell A1, type Index, and then press Enter or Return.
- Don't worry if the field already contains a cell address.
- You can’t use spaces in the cell name, so you’ll have to use something like “Index” or “TableofContents.”
-
Click any of the sheets in your workbook. Now you'll create your back button. Once you create a back button on one sheet, you can just copy and paste it onto other sheets.
-
Click the Insert tab. It's at the top of the screen.[2]
-
Select Shapes. Depending on your version of Excel, you might see this in a section of the menu called Illustrations. The Shapes icon looks like a white circle overlapping a blue square.[3]
-
Click a shape for your button. For example, if you want to create a back-arrow icon sort of like your web browser's back button, you can click the left-pointing arrow under the "Block Arrows" header.
-
Click the location where you want to place the button. Once you click, the shape will appear. If you want, you can change the color and look using the options at the top, and/or resize the shape by dragging any of its corners.[4]
- For some kinds of shapes, like rectangles, you’ll need to click and drag your cursor to make the shape appear.
-
Type some text onto the shape. The text you type should be something like "Back to Index." You can double-click the shape to place the cursor and start typing right onto the actual shape
- You might need to drag the corner of the shape to resize it so the text fits.
- To place a text box on or near the shape before typing, just click the Shape Format menu at the top (while the shape is selected), click Text Box in the toolbar, and then click and drag a text box.
- You can stylize the text using the options in Text on the toolbar while the shape is selected.
-
Right-click the shape and select Link or Hyperlink. This opens the Insert Hyperlink dialog.[5]
- If you’re using a Mac with no right mouse button, Ctrl-click the shape to open the context menu.
-
Click the Place in This Document icon. It's in the left panel.
- In Excel for Mac, click the This Document tab near the top of the Insert Hyperlink dialog.
-
Select your index under "Defined Names" and click OK. You might have to click the + next to the column header to see the Index option. This makes the text in the shape a clickable hyperlink that takes you right to the index.
-
Copy and paste the hyperlink to other sheets. To do this, just right-click the shape (or Ctrl-click on a Mac) and select Copy. Then, you can paste it onto any other page by right-clicking the desired location and selecting the first icon under "Paste Options" (the one that says "Use Destination Theme" when you hover the mouse over it).[6]
Expert Q&A
Video
Tips
References
- ↑ https://learn.microsoft.com/en-us/office/dev/scripts/resources/samples/table-of-contents
- ↑ https://support.microsoft.com/en-us/office/add-shapes-0e492bb4-3f91-43b5-803f-dd0998e0eb89
- ↑ https://support.microsoft.com/en-us/office/add-shapes-0e492bb4-3f91-43b5-803f-dd0998e0eb89
- ↑ https://support.microsoft.com/en-us/office/work-with-links-in-excel-7fc80d8d-68f9-482f-ab01-584c44d72b3e
- ↑ https://support.microsoft.com/en-us/office/work-with-links-in-excel-7fc80d8d-68f9-482f-ab01-584c44d72b3e
- ↑ https://support.microsoft.com/en-us/office/work-with-links-in-excel-7fc80d8d-68f9-482f-ab01-584c44d72b3e
- ↑ https://support.microsoft.com/en-us/office/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd
- ↑ https://support.microsoft.com/en-us/office/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd
About This Article
To create a table of contents in Excel, you can use the "Defined Name" option to create a formula that indexes all sheet names on a single page. Then, you can use the INDEX function to list the sheet names, as well as the HYPERLINK function to create quick links to each sheet.












