Skip Worksheets in For Next Loop

KDBrown

New Member
Joined
Jan 11, 2010
Messages
14
Good morning experts!

I'm trying to loop through worksheets as follows:

If ws.Name <> "DataTable" And ws.Name <> "Summary" Then ws.Activate
code to do some copy/paste stuff ....
Next ws

Try as I may, I can't get the code to skip the worksheets named "DataTable" and "Summary". Based on other posts, I've tried swapping out the And for an Or. Also tried using LCase(ws.Name), to no avail. Note that I'm acually trying to skip several other sheets as well but only listed two here for simplicity.

I suspect the problem is quite simple and right in front of my eyes, but I'm just not seeing it. I'm using Excel 2007 and know just enough VBA to limp along.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You probably need

Code:
If ws.Name <> "DataTable" And ws.Name <> "Summary" Then 
ws.Activate
'code to do some copy/paste stuff ....
End If
Next ws
 
Upvote 0
The other code should also be in the If...Then loop

Code:
If ws.Name <> "DataTable" And ws.Name <> "Summary" Then 
ws.Activate
code to do some copy/paste stuff ....
End If
Next ws

I think it should work with that change.
 
Upvote 0

Forum statistics

Threads
1,215,239
Messages
6,123,816
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top