Solved

Macro to Run Multiple macros in sequence

Posted on 2010-08-24
10
1,323 Views
Last Modified: 2012-05-10
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
Comment
Question by:tutonaranjo
  • 5
  • 4
10 Comments
 
LVL 13

Expert Comment

by:MWGainesJR
Comment Utility

Sub Button1_Click()



'sort1 code



'sort2 code



'sort3 code



msgbox "Done"



end sub

Open in new window

0
 
LVL 6

Expert Comment

by:steverice
Comment Utility
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
 

Author Comment

by:tutonaranjo
Comment Utility
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
 
LVL 13

Expert Comment

by:MWGainesJR
Comment Utility
use this method:
Worksheets(1).calculate
0
 
LVL 6

Accepted Solution

by:
steverice earned 500 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:steverice
Comment Utility
Thanks MWGainsJR - I was on it....
0
 
LVL 13

Expert Comment

by:MWGainesJR
Comment Utility
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
 
LVL 6

Expert Comment

by:steverice
Comment Utility
You're absolutely right - but i was giving the option to select a range within the sheet to re-calculate.
0
 
LVL 13

Expert Comment

by:MWGainesJR
Comment Utility
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
 
LVL 6

Expert Comment

by:steverice
Comment Utility
snore
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now