calling modules in order on each sheet

vssa

New Member
Joined
Feb 18, 2012
Messages
16
Hi, im having trouble running a set of modules in order on a sheet then when thats done loop the seem sequence through all the sheets in the file

so far ive got
Code:
Sub Run_all()
 Dim sh As Worksheet
 
 For Each sh In ThisWorkbook.Worksheets
    sh.activate
    
    Call macro_1
    Call macro_2
    Call macro_3
    Call macro_4
    Call macro_5
    
     Next sh
End Sub

but wont that just run all of them at the same time i want it to run macro_1 when thats done run macro_2 ect when its run all of them move to the next sheet and do that same again

the only other thing is is there a way that i can put all of the macros into 1 larger macro that will loop through all the steps and then move onto the next sheet and do the same

hope that makes sense

regards
 
Last edited by a moderator:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Then you will need to loop through all sheets and call each macro one at a time. I do not know another way of coding this.
 
Upvote 0
Hi vog,

i just had a read over the question and i dont think ive made it very clear,

what i meant was on sheet1:
run macro_1
then run macro_2
then run macro_3
then run macro_4
then run macro_5

when all the macros have run then move the the next sheet and run the macros, then the next sheet ect ect
 
Upvote 0
I think you are saying you want this:

Code:
Sub Run_all2()
Dim i as long
	 
	for i = 1 to thisworkbook.worksheets.count
		worksheets(i).activate
		Call macro_1
	next i

	for i = 1 to thisworkbook.worksheets.count
		worksheets(i).activate
		Call macro_2
	next i

	for i = 1 to thisworkbook.worksheets.count
		worksheets(i).activate
		Call macro_3
	next i

	for i = 1 to thisworkbook.worksheets.count
		worksheets(i).activate
		Call macro_4
	next i

	for i = 1 to thisworkbook.worksheets.count
		worksheets(i).activate
		Call macro_5
	next i

End Sub

That will work. To code this more compactly:

Code:
Sub Run_all3()
dim i as long
dim a
dim sh as worksheet
	 
	a = array("macro_1", "macro_2", "macro_3", "macro_4", "macro_5")
	for i = 0 to Ubound(a)
		for each sh in thisworkbook.worksheets
			sh.activate
			application.run a(i)
		next sh
	next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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