Excluding sheet in loop
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 |
Excluding sheet in loop
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 -----Original Message----- 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 . |
Excluding sheet in loop
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 david wrote in message ... 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 |
All times are GMT +1. The time now is 09:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com