Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List sheet names in excel while skipping the unwanted sheets

How can a list of sheet names be generated in excel, while skipping the unwanted sheets?

I would like to list “Expenses”, “Revenue”, and “Advisors” (Green tabs). While skipping “Template”, “Reference Data 1”, and “Reference Data 2” (Black tabs).
I receive an error while using the code below.

All help and guidance is appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Sub List_Sheets()
'
' List_Sheets Macro
'
Dim ws As Worksheet
Dim x As Integer
 
x = 1 'Starting Row
 
For Each ws In Worksheets
    If InStr(ws.Name, "Template") Then 'Skip "Template" also skip "Referance data 1" and "Referance data 2"
        GoTo NextIteration
    Sheets("Summary").Cells(x, 1) = ws.Name 'Starting collunm 1 also know as A
    x = x + 1
NextIteration:
Next ws
 
End Sub

Error received

>Solution :

This part:

If InStr(ws.Name, "Template") Then 'Skip "Template" also skip "Referance data 1" and "Referance data 2"
        GoTo NextIteration
    Sheets("Summary").Cells(x, 1) = ws.Name 'Starting collunm 1 also know as A
    x = x + 1
NextIteration:

should become:

If InStr(ws.Name, "Template") > 0 or _
     InStr(ws.Name, "Reference") > 0  Then GoTo NextIteration
        
     Sheets("Summary").Cells(x, 1) = ws.Name 'Starting collunm 1 also know as A
     x = x + 1
NextIteration:
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading