Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4197
  • Last Modified:

Macro to Run Multiple macros in sequence

I have recorded several amcros in excel
Lets call them Sort1, Sort2, Sort3
I would like to have a button, that when pressed, runs these macros in sequence...first Sort1, then Sort2, etc...
at then end ideally it would print "Done" to a specific cell

Can someone help out with the code to have it run the other macros?
0
tutonaranjo
Asked:
tutonaranjo
  • 5
  • 4
1 Solution
 
MWGainesJRCommented:

Sub Button1_Click()

'sort1 code

'sort2 code

'sort3 code

msgbox "Done"

end sub

Open in new window

0
 
stevericeCommented:
if sort1, sort2, sort3 are already macros, you can invoke them using the 'Call' statement:

Sub Button1_Click()

     call sort1
     call sort2
     call sort3

msgbox "Done"

end sub
0
 
tutonaranjoAuthor Commented:
Steverice,

Thanks for your answer.
Could you help me with one last push?

My excel spreadsheet is set not to calculate automatically.

so the macros you gav eme is perfect, but perhaps it could use a tweak.

How do I get it to do the following?

1. Calculate  a specific worksheet 1 (tab)
2. then run sort 1
3. Calculate a specific worksheet 2 (tab)
4. ten run sort 2

you catch my drift...

thanks!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MWGainesJRCommented:
use this method:
Worksheets(1).calculate
0
 
stevericeCommented:
Be careful using this method. The calculation at sheet level assumes that any dependencies in other sheets are already calculated - if they are not, the result in the sheet being recalculated will be based on an uncalculated result (I think that makes sense)


Sub Button1_Click()
    Sheets("worksheet 1").Select
    Range("a1:z999").select 'change this to your actual calculation range
    range.calculate
    call sort1
    Sheets("worksheet 2").Select
    Range("a1:z999").select 'change this to your actual calculation range
    range.calculate
    call sort2
    call sort3

msgbox "Done"

end sub

Open in new window

0
 
stevericeCommented:
Thanks MWGainsJR - I was on it....
0
 
MWGainesJRCommented:
You don't need any select codes:
Sub Button1_Click()  
    Sheet1.calculate 'or Worksheets(1).calculate or Worksheets("Sheet1").calculate
    call sort1  
    sheet2.calculate 'or Worksheets(2).calculate or Worksheets("Sheet2").calculate
    call sort2
    sheet3.calculate 'or Worksheets(3).calculate or Worksheets("Sheet3").calculate
    call sort3  
  
msgbox "Done"  
  
end sub

Open in new window

0
 
stevericeCommented:
You're absolutely right - but i was giving the option to select a range within the sheet to re-calculate.
0
 
MWGainesJRCommented:
Even with calculating a certain range, you don't need to select the sheet nor range
sheet1.range("A1:Z999").calculate
=)
Selecting is hardly ever necessary in VB code and only dirties up the code.
0
 
stevericeCommented:
snore
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now