Run Macro on all worksheets except 2

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I presently have a workbook with a number of sheets (The number will vary from 1 to over 50). At the end of the year I save the workbook for the current year and then save it again for the new year. At that time I run a macro (named "ClearForNewYear") on each sheet in the the new workbook to clear some data, making it ready for the new year. I need to run this for every sheet in the workbook except sheet1 (Named "1Master") and sheet4 (Named "ZZSummary"). The macro I am using works fine but I have to currently open each worksheet and then run the macro. Can anyone help me with the code to just run the macro once and it clears the necessary data from all the worksheets in the workbook except the 2 I have mentioned?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You can create a macro to loop through all worksheets except for those two and run your macro.
The structure would look something like this:
VBA Code:
Sub RunMacro()

    Dim ws As Worksheet
   
    For Each ws In Worksheets
        If ws.Name <> "1Master" And ws.Name <> "ZZSummary" Then
            ws.Activate
            'Call your macro to run here
        End If
    Next ws
   
End Sub

Simply replace the
VBA Code:
'Call your macro to run here
line with the name of your macro.

If it was named "Macro1", that line would look like:
VBA Code:
Call Macro1
 
Upvote 0
Solution
You can create a macro to loop through all worksheets except for those two and run your macro.
The structure would look something like this:
VBA Code:
Sub RunMacro()

    Dim ws As Worksheet
  
    For Each ws In Worksheets
        If ws.Name <> "1Master" And ws.Name <> "ZZSummary" Then
            ws.Activate
            'Call your macro to run here
        End If
    Next ws
  
End Sub

Simply replace the
VBA Code:
'Call your macro to run here
line with the name of your macro.

If it was named "Macro1", that line would look like:
VBA Code:
Call Macro1
Hi Joe4. This works perfectly. Thank you so much for this quick reply and assistance - Much appreciated.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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