Hey folks, I have found several examples of how to make a TABLE of Contents (single column), but I have only found one which displays multiple columns.
The code below works well, however, when I attempt to "exclude" additional sheets, I get an array error.
I am not good at arrays, so I can't seem to figure out why it is erroring out when I attempt to exclude more than 1 sheet.
There are six sheets I want to exclude from the Table of Contents: Instructions, Version_Data, Table of Contents, Summary, Tutoring Attendance, and Master. I have commented it out to make the code generate the TOC.
Here is the lines of code which I changed to exclude the six sheets: (commented out).
Here is the code to create the TOC: The Set sht = Worksheets(myArray(x)) is where the code errors out.
The end result works well for a multiple column TOC, which is alphabetized and divided equally across all the columns. Just can't get the code to exclude the names in YELLOW below.
Any help would be appreciated.
The code below works well, however, when I attempt to "exclude" additional sheets, I get an array error.
I am not good at arrays, so I can't seem to figure out why it is erroring out when I attempt to exclude more than 1 sheet.
There are six sheets I want to exclude from the Table of Contents: Instructions, Version_Data, Table of Contents, Summary, Tutoring Attendance, and Master. I have commented it out to make the code generate the TOC.
Here is the lines of code which I changed to exclude the six sheets: (commented out).
VBA Code:
For Each sht In ActiveWorkbook.Worksheets
'If sht.Name <> "Instructions" And sht.Name <> "Version_Data" And sht.Name <> "Table Of Contents" _
And sht.Name <> "Summary" And sht.Name <> "Tutoring Attendance" And sht.Name <> "Master" Then
If sht.Name <> ContentName And sht.Visible = True Then
myArray(x + 1) = sht.Name
x = x + 1
End If
'End If
Next sht
Here is the code to create the TOC: The Set sht = Worksheets(myArray(x)) is where the code errors out.
VBA Code:
'Create Table of Contents
x = 1
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 + 3, 2 * y), "", _
SubAddress:="'" & sht.Name & "'!A1", _
TextToDisplay:=sht.Name
End With
x = x + 1
End If
Next z
Next y[CODE=vba]
The end result works well for a multiple column TOC, which is alphabetized and divided equally across all the columns. Just can't get the code to exclude the names in YELLOW below.
Any help would be appreciated.