Exclude worksheets from loop with a list

0 votes

I'm collecting data on the first worksheet by iterating over all of my worksheets in a loop. A list of worksheets that are defined by their names in a list on the first worksheet is what I now wish to omit.

I could do so one by one as follows:

dim ws as worksheet
For each ws in ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" and ws.name <> "Sheet2"

and so on.

BUT Since the data will change in the future I don't want to edit this code every time the "exclude-list" changes.

Feb 11, 2023 in Others by narikkadan
• 63,600 points
334 views

1 answer to this question.

0 votes

You can achieve this by making a sheet called Exclude. Write Exclude on the first line of column A. Your other sheets should be removed next. Use the code below to finish.

Dim Lastrow As Integer
Lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row

Set rs = ws.Range("A1:A1" & Lastrow)


For Each ws In ThisWorkbook.Worksheets
    If Not rs.Find(ws.Name) Is Nothing Then
        'Your code
    End If
Next
answered Feb 11, 2023 by Kithuzzz
• 38,000 points

Related Questions In Others

0 votes
0 answers

How to drop all tables from a database with one SQL query?

What if we don't want to type ...READ MORE

May 28, 2022 in Others by Sohail
• 3,040 points
383 views
0 votes
0 answers

Creating a sequential list of letters with R

I want to be able to create a ...READ MORE

Jun 1, 2022 in Others by avinash
• 1,840 points
508 views
0 votes
0 answers

How to drop all tables from a database with one SQL query?

drop all tables without typing name. Is ...READ MORE

Jun 7, 2022 in Others by polo
• 1,480 points
293 views
0 votes
1 answer

Multiple find and replace in MS Word from a list in MS Excel

If I understand you correctly, you want ...READ MORE

answered Oct 28, 2022 in Others by narikkadan
• 63,600 points
733 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,232 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,684 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
942 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,079 views
0 votes
1 answer
0 votes
1 answer

VBA - Build a Two-Column Array By Looping Through one Array with a Specific Criteria and Selecting From Another Array

As already mentioned as comment: Loop over ...READ MORE

answered Mar 24, 2023 in Others by Kithuzzz
• 38,000 points
462 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP