Professional Documents
Culture Documents
Macro Samples
Macro Samples
I got this macro online that adds a Table of Contents worksheet to easily navigate to any tab.
My workbook:
THE IDEA:
a. Improve the table of contents so it will have sections, and also will display text notes
together with the worksheet name. Notes does not need to be clickable (link)
b. Freze the Contents worksheet position, even if I have several worksheets and scroll to
to the sides, the Table of Contents worksheet will be always visible.
Open
Project delayed due to budget constraints
Closed Won
Will call next week to sign agreement
Closed Lost
Lost to Xyz company, on bid war
Content of a worksheet:
This tab should be fixed. If I scroll to the side to see other tabs, it will aways be visible
Current Macro:
Sub TableOfContents_Create()
'Inputs
ContentName = "Contents"
'Optimize Code
Application.DisplayAlerts = False
Application.ScreenUpdating = False
x=x+1
End If
Next sht
For y = 1 To ColumnCount
For z = 1 To WorksheetFunction.RoundUp(shtCount / ColumnCount, 0)
If x <= UBound(myArray) Then
Set sht = Worksheets(myArray(x))
sht.Activate
With Content_sht
.Hyperlinks.Add .Cells(z + 2, 2 * y), "", _
SubAddress:="'" & sht.Name & "'!A1", _
TextToDisplay:=sht.Name
End With
x=x+1
End If
Next z
Next y
ExitSub:
'Optimize Code
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub