

'Refresh all pivot tables caches in the active workbook Dim i As Integer For i = 1 To 'Code to update formulas 'Run the refresh pivots macro from this macro Call Refresh_All_Pivots 'Code to update the source data 'Run the refresh pivots macro from this macro Call Refresh_All_Pivots

In the code sample below there are two macros that are both calling the macro to refresh all the pivot tables in the workbook. One common task is to refresh all the pivot tables in the workbook. I use this technique of calling other procedures a lot. Example: Call the Refresh All Pivot Tables Macro from Other Macros

It may be a few extra letters to type, but it will really help you and others read your code more quickly when debugging it in the future. My personal opinion is that it is best to always use the Call statement when calling another macro. However, you will need the Call statement if your macro contains parameters (variables) that you want to pass through to the called macro or function. You can leave the word Call out, and just type in the macro name. 'When Macro2 is complete the code will continue 'to run below the call line in this macro 'Place code here to run AFTER Macro2 runs End SubĪnother thing to note is that you do not always have to use the Call statement to call another macro. 'Place code here to run before calling Macro2 'The following line will run Macro2 Call Macro2 Once it is complete, Macro1 will continue to run the next line of code under the Call statement. Once the Call line is hit, Macro2 will be run completely to the end. It's important to note that the two macros DO NOT run at the same time. The example below shows how to call Macro2 from Macro1. Just type the word Call then space, then type the name of the macro to be called (run). Here is an example of how to run another macro from a macro using the Call Statement. VBA Example: Run Another Macro from a Macro We can have several macros calling another macro.

This helps us keeps our macros shorter and easier to manage. Did you know you can run other macros from a macro? This is a very efficient practice that allows us to reuse macros, so we don't have duplicate code snippets throughout our macros.
