Forum Discussion

RShaw1972's avatar
RShaw1972
Copper Contributor
Sep 30, 2023
Solved

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 ...
  • HansVogelaar's avatar
    Sep 30, 2023

    RShaw1972 

    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

Resources