Hello,
I hope someone helps me get the code right.
I create a sheet name list (VBA) but I want to skip sheet names that contain "alt"
here is my code
Sub TOC_List()
'Create Table of Contents on this TOC sheet
Dim ws As Worksheet
Dim wsTOC As Worksheet
Dim i As Long
Application.ScreenUpdating = False
'Set variables
Const bSkipHidden As Boolean = False 'Change this to True to list hidden sheets
Const sTitle As String = "A100"
Const sHeader As String = "A100"
Set wsTOC = Me 'can change to a worksheet ref if using in a regular code module
i = 1
'Clear Cells
Range("TableScope").Clear
'Create TOC list
With wsTOC.Range(sHeader)
' wsTOC
'Create list
For Each ws In ThisWorkbook.Worksheets
'Skip TOC sheet
If ws.Name <> Sheet2.Name Then
If ws.Name <> Sheet5.Name Then
If ws.Name <> Data.Name Then
if ws.Name <> sheet that contains "alt"
'Skipping hidden sheets can be toggled in the variable above
If bSkipHidden Or ws.Visible = xlSheetVisible Then
.Offset(i).Value = i
wsTOC.Hyperlinks.Add Anchor:=.Offset(i, 1), _
Address:="", _
SubAddress:="'" & ws.Name & "'!A1", _
TextToDisplay:=ws.Name
i = i + 1
Else
ws.Visible = xlSheetHidden
End If
End If
End If
End If
Next ws
End With
Application.ScreenUpdating = True
End Sub
I hope someone helps me get the code right.
I create a sheet name list (VBA) but I want to skip sheet names that contain "alt"
here is my code
Sub TOC_List()
'Create Table of Contents on this TOC sheet
Dim ws As Worksheet
Dim wsTOC As Worksheet
Dim i As Long
Application.ScreenUpdating = False
'Set variables
Const bSkipHidden As Boolean = False 'Change this to True to list hidden sheets
Const sTitle As String = "A100"
Const sHeader As String = "A100"
Set wsTOC = Me 'can change to a worksheet ref if using in a regular code module
i = 1
'Clear Cells
Range("TableScope").Clear
'Create TOC list
With wsTOC.Range(sHeader)
' wsTOC
'Create list
For Each ws In ThisWorkbook.Worksheets
'Skip TOC sheet
If ws.Name <> Sheet2.Name Then
If ws.Name <> Sheet5.Name Then
If ws.Name <> Data.Name Then
if ws.Name <> sheet that contains "alt"
'Skipping hidden sheets can be toggled in the variable above
If bSkipHidden Or ws.Visible = xlSheetVisible Then
.Offset(i).Value = i
wsTOC.Hyperlinks.Add Anchor:=.Offset(i, 1), _
Address:="", _
SubAddress:="'" & ws.Name & "'!A1", _
TextToDisplay:=ws.Name
i = i + 1
Else
ws.Visible = xlSheetHidden
End If
End If
End If
End If
Next ws
End With
Application.ScreenUpdating = True
End Sub