Forum Discussion
RShaw1972
Sep 30, 2023Copper Contributor
Excel VBA - Listing of Specifically-named Worksheets
Hello everyone. I am using the following code to create a list of worksheets whose names contain "(M)" in their name: Sub List_Worksheets() ' Clear existing list Range("AC1").Select ...
- Sep 30, 2023
Like this:
Sub List_Worksheets() Dim i As Long Dim r As Long Application.ScreenUpdating = False ' Clear existing list Range("AC:AC").ClearContents ' Create list of specific worksheet names For i = 1 To Sheets.Count - 3 If Sheets(i).Name Like "* (M)" Then r = r + 1 Range("AC" & r).Value = Sheets(i).Name End If Next i Application.ScreenUpdating = True End Sub
HansVogelaar
Sep 30, 2023MVP
Like this:
Sub List_Worksheets()
Dim i As Long
Dim r As Long
Application.ScreenUpdating = False
' Clear existing list
Range("AC:AC").ClearContents
' Create list of specific worksheet names
For i = 1 To Sheets.Count - 3
If Sheets(i).Name Like "* (M)" Then
r = r + 1
Range("AC" & r).Value = Sheets(i).Name
End If
Next i
Application.ScreenUpdating = True
End Sub
- RShaw1972Sep 30, 2023Copper ContributorWorked beautifully! Thank-you.