Do not run macro on certain sheets...

cmhoz

Active Member
Joined
Aug 20, 2006
Messages
268
Okay...

I have a macro (or will when i write it!) that loops through each worksheet in the file and runs a macro. This is fine.

However, there a 3 sheets in the files that I want the macro to NOT run on.

So, I was thinking that I would do a select case for these three that lead to and exit sub and a case else that runs the macro.

I'm drawing a blank on one little bit - the syntax to use to determine the name of the sheet...
eg: select case sheets
case sheets("sheet1")
exit sub

select case sheets doesn't work... and apparently neither does my brain!

Thanks!!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

How about something like
Code:
for each ws in worksheets
  select case ws.name
   case "name1","name2","name3"
    exit sub
    case else
   do your stuff
 end select

next ws


Tony
 

cmhoz

Active Member
Joined
Aug 20, 2006
Messages
268
yep... beautiful.

Thanks... helps to have an extra brain once in a while!
 

Forum statistics

Threads
1,136,877
Messages
5,678,290
Members
419,753
Latest member
Sallylwy

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
Top