In some excel files, I am using a macro to tell it to run another macro according to some specific criterias.
When I use the macro ?
This macro is useful, for instance, when I am doing a report based on the year and the month. For example, if it is January, I want it to do a yearly report and if it is another month, to do the monthly report.
How to create the macro ?
Read How to create, edit, hide and select a macro in an excel report
How to create the button to associate it with the macro ?
Read How to create a button and associated it to a macro in an excel report
How to use the macro ?
The macro has to be with the other macros that you are going to ask to execute so either:
- In the same Microsoft excel object, for instance, sheet1
- Or in the same module, for instance, module1
For instance, if your macro1 is in the “sheet1”, put this one also in the “sheet1”. If it is not in the “sheet1” but in the “module1”, put it in the “module1”. It will not work if your macro1 is in the “sheet1” and you put this macro in the “module1”.
How is the macro ?
Copy the code below and paste it into your macro. You will see my comments in green if exist so follow the help to adapt to your need.
' meetrequirement is your code
If meetrequirement Then
Call macro1 ' if yes, run this macro
Call macro2 ' if no, run this macro