Running a macro on multiple worksheets at once

jessieo387

New Member
Joined
Jun 10, 2009
Messages
40
I want to run a macro called Macro1 on about 40 different worksheets in the same workbook. I wrote this macro to do that:

Sub Run_all_solver_macros
Call Macro1
End Sub

Its not working I think because this macro isn't need on every worksheets, how do I make this refernece only to the worksheets it needs to run on?

Thanks!

Jessica
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this: -
Code:
Sub Run_all_solver_macros
Dim Sh as Worksheet.
For Each worksheet in Sheets("Sheet1",,,,,,,,,Sheetn") 'n = sheet number/or sheet name
call macro1
Next
 
Upvote 0
I tried that and I get run-time error 91. This is the new code


Code:
Sub Run_all_solver_macros()
Dim Sh As Worksheet
For Each Worksheet In Sh(Jan_1, Jan_2, Jan_3, Feb_1, Feb_2, Feb_3)
Call Macro1
Next
End Sub
 
Upvote 0
I changed the code to:

Code:
Sub Run_all_solver_macros()
Dim Sheets As Worksheet
For Each Worksheet In Sheets("Jan_1", "Jan_2", "Jan_3", "Feb_1", "Feb_2", "Feb_3")
Call Macro1
Next
End Sub

And still get the same run-time error 91 :(
 
Upvote 0
I was not able to access this site since morning. i have just seen your post here -

Try this -

Code:
Sub Run_all_solver_macros()
Dim wsh As Worksheet
Sheets(Array("Jan_1", "Jan_2", "Jan_N")).Select 
For Each wsh In ActiveWindow.SelectedSheets
Call Macro1
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,684
Members
449,116
Latest member
HypnoFant

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