I have some code that works well for a Table of contents on the Workbook Index page, that chooses the heading of each sheet (C5 of each sheet), and puts the headings in a "table of contents list" on the index page (starting in C11) (see code below). It allows a table of contents to "list/show" only "un-hidden sheets".
The problem I am having is I'm trying to put it into a new Workbook (same types of pages) but I'm not sure how to "change / edit" it to work.
My new workbook is named "NEWEST NEW" (If it matters).
BTY, I'm very green at this. Any Help?
Thanks / Richard
[Option Explicit
'=========================================================================================
'=========================================================================================
Sub UpdateIndexWorksheet()
Const sINDEX_SHEETNAME As String = "Workbook Index"
Const sSHEETNAME_CELL As String = "C5"
Const sHEADER_CELL As String = "C10"
Dim rHeaderCell As Range
Dim wksIndex As Worksheet
Dim iRowNo As Integer
Dim wks As Worksheet
Set wksIndex = ThisWorkbook.Worksheets(sINDEX_SHEETNAME)
Set rHeaderCell = wksIndex.Range(sHEADER_CELL)
Call ClearIndexCells(wksIndex:=wksIndex, rHeaderCell:=rHeaderCell)
iRowNo = 1
For Each wks In ThisWorkbook.Worksheets
If wks.Visible = xlSheetVisible Then
rHeaderCell.Offset(iRowNo, 0).Value = wks.Range(sSHEETNAME_CELL)
iRowNo = iRowNo + 1
End If
Next wks
End Sub
'=========================================================================================
'=========================================================================================
Private Sub ClearIndexCells(wksIndex As Worksheet, rHeaderCell As Range)
Dim rFirstCell As Range
Dim rLastCell As Range
Dim rLastRow As Range
Set rFirstCell = rHeaderCell.Offset(1, 0)
With wksIndex
Set rLastRow = .UsedRange.Rows(.UsedRange.Rows.Count)
End With
Set rLastCell = Intersect(rLastRow, rHeaderCell.EntireColumn)
Range(rFirstCell, rLastCell).ClearContents
End Sub]
Bookmarks