Excluding sheet in loop

  • Thread starter Thread starter david
  • Start date Start date
D

david

I am trying to get a loop that will go to all sheets in a
book and clear certain cells. There are 2 sheets that I
don't want to delete anything on. The names of these
sheets don't change, but the rest of the sheets do. My
loop works to delete the cells off of all of the sheets,
but I want to exclude these two sheets. How do I exclude 2
sheets from that loop?

Thanks,
David
 
Piece of cake:

Activeworkbook.Sheets(1).Select
For X = 1 to Activeworkbook.Sheets.Count
If Sheets(X).Name = "whatever" or Sheets(X).Name
= "Whatever else" then
X = X + 1
Else
do your thing
End If
Sheets(X).Select
Next X
 
Dim sh as worksheet
for each sh in thisworkbook.Worksheets
if not (sh.Name = "Sheet1" or sh.Name = "Sheet2") then
'process the sh
sh.Range("A1").ClearContents 'as an example
end if
Next

Regards,
Tom Ogilvy
 
Back
Top