Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Create a Table of Contents in Excel using VBA

This document provides a step-by-step guide to creating a Table of Contents (TOC) in Excel using VBA. It includes instructions on opening the VBA editor, inserting a module, and using a provided code snippet to generate the TOC. Users can customize the starting cell and sheet name for the TOC and run the macro to create it.

Uploaded by

shamielpe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Create a Table of Contents in Excel using VBA

This document provides a step-by-step guide to creating a Table of Contents (TOC) in Excel using VBA. It includes instructions on opening the VBA editor, inserting a module, and using a provided code snippet to generate the TOC. Users can customize the starting cell and sheet name for the TOC and run the macro to create it.

Uploaded by

shamielpe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Create a Table of Contents in Excel using VBA

Here is a step-by-step guide on how to create a Table of Contents in Excel using VBA:

Step 1: Open your Excel workbook and press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

Step 2: Click on Insert in the menu bar and select Module to insert a new module.

Step 3: Copy and paste the following VBA code into the module:

vba

Copy code

Sub CreateTOC()

Dim ws As Worksheet

Dim rng As Range

Dim i As Integer

i=1

Set rng = Sheets("Sheet1").Range("A1") ' Change "Sheet1" to the name of the worksheet where you want
to create the TOC

For Each ws In ThisWorkbook.Sheets

rng.Offset(i, 0).Value = i

rng.Offset(i, 1).Value = ws.Name

i=i+1

Next ws

End Sub

Step 4: Modify the code as needed to customize the Table of Contents. You can change the starting cell of
the TOC by modifying the Range("A1") value and the sheet name where the TOC is created by changing the
Sheets("Sheet1") value.

Step 5: Run the macro by pressing F5 or selecting Run from the menu bar.

Step 6: Your Table of Contents will be generated in the specified worksheet with the index number and name
of each sheet in the workbook.

You can further customize the appearance and functionality of the Table of Contents by adding additional
features to the VBA code.

You might also like