Excel.with.Layael

  • Home
  • Excel.with.Layael

Excel.with.Layael ➡️ Excel Sheets - Shortcuts and Tricks
➡️ A learning curve is essential to growth

19/10/2022

Create Table of Contents on Excel


Under the Developer tab, click Visual Basic.

Click Insert then click Module.

Copy and paste the following code:
Option Explicit
Sub Create_ToC()
Dim wbBook As Workbook
Dim wsActive As Worksheet
Dim wsSheet As Worksheet
Dim lnRow As Long
Set wbBook = ActiveWorkbook
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With

On Error Resume Next
With wbBook
.Worksheets("ToC").Delete
.Worksheets.Add Before:=.Worksheets(1)
End With
On Error GoTo 0
Set wsActive = wbBook.ActiveSheet
With wsActive
.Name = "ToC"
With .Range("A1")
.Value = VBA.Array("Table of Contents")
.Font.Bold = True
End With
End With
lnRow = 2

For Each wsSheet In wbBook.Worksheets
If wsSheet.Name - wsActive.Name Then
wsSheet.Activate
With wsActive
.Hyperlinks.Add .Cells(lnRow, 1), "", _
SubAddress:="'" & wsSheet.Name & "'!A1", _
TextToDisplay:=wsSheet.Name

End With
lnRow = lnRow + 1
End If
Next wsSheet
wsActive.Activate
wsActive.Columns("A:B").EntireColumn.AutoFit
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub

To use Visual Basic Macros, you will need to save the file as an Excel Macro Enabled Workbook.

Click Macros under the Developer tab.

Select the Create_ToC Macro and Run it. If your original worksheet is named differently, you may need to change all instances in the VBA script of ToC.

A table of contents of all the worksheets should be created.

14/10/2022

Remove Duplicates .with.layael

14/10/2022

Proper Text .with.layael

14/10/2022

Autosum Multiple Columns&Rows
.with.layael

14/10/2022

Creating Sparklines
.with.layael

14/10/2022

Inserting Dividers
.with.layael

14/10/2022

Screenshot Workbook to new Workbook .with.layael

22/09/2022

Import PDF into Excel .with.layael

21/09/2022

Lower/Upper/Proper Name Changes .with.layael

21/09/2022

Remove Blanks - Columns & Rows .with.layael

21/09/2022

Create Barcodes .with.layael

20/09/2022

XLOOKUP - Using 3 Criterias
.with.layael

Address


Telephone

+61434644287

Website

Alerts

Be the first to know and let us send you an email when Excel.with.Layael posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The Business

Send a message to Excel.with.Layael:

Shortcuts

  • Address
  • Telephone
  • Alerts
  • Contact The Business
  • Claim ownership or report listing
  • Want your business to be the top-listed Media Company?

Share