Running a macro accross all sheets in a workbook

sphingo

New Member
Joined
Jul 15, 2011
Messages
2
I am needing to create a macro that runs the following code accross all the sheets in a workbook. The number of sheets changes from workbook to workbook and one the macro's creates a chart so I need the macro to run in one sheet then move to the next so forth and so on. Any help would be greatly appreciated.

Sub AMaster()
'
' AMaster Macro
'
'
Application.Run "PERSONAL.XLSB!na_to_0"
Application.Run "PERSONAL.XLSB!label2"
Application.Run "PERSONAL.XLSB!Calc3"
Application.Run "PERSONAL.XLSB!Fudge3"
Application.Run "PERSONAL.XLSB!Fudge4"
Application.Run "PERSONAL.XLSB!Fudge5"
Application.Run "PERSONAL.XLSB!table"
Application.Run "PERSONAL.XLSB!table2"
Application.Run "PERSONAL.XLSB!table3"
Application.Run "PERSONAL.XLSB!Chart"
Application.Run "PERSONAL.XLSB!label"
Application.Run "PERSONAL.XLSB!Format"
Application.Run "PERSONAL.XLSB!PrintArea"
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Code:
Sub AMaster()
Dim ws as Worksheet
For each ws in ThisWorkbook.Sheets
    Application.Run "PERSONAL.XLSB!na_to_0"
    Application.Run "PERSONAL.XLSB!label2"
    Application.Run "PERSONAL.XLSB!Calc3"
    Application.Run "PERSONAL.XLSB!Fudge3"
    Application.Run "PERSONAL.XLSB!Fudge4"
    Application.Run "PERSONAL.XLSB!Fudge5"
    Application.Run "PERSONAL.XLSB!table"
    Application.Run "PERSONAL.XLSB!table2"
    Application.Run "PERSONAL.XLSB!table3"
    Application.Run "PERSONAL.XLSB!Chart"
    Application.Run "PERSONAL.XLSB!label"
    Application.Run "PERSONAL.XLSB!Format"
    Application.Run "PERSONAL.XLSB!PrintArea"
Next ws
End Sub
 
Upvote 0
You may need to amend some of the codes in your macro if you are using specific sheet names or activework etc.

add this to the beginning:

Dim sht as worksheets

for each sht in activeworkbook.worksheets

'your code here

next sht
 
Upvote 0
none of the code is sheet specific. I have worked that out already. But when I run what you say it doesn't move to the next sheet but continually loops on whatever sheet is selected.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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