How to Merge Two Macros in Excel
Macros consist of Visual Basic programming code. They are convenient to use in Microsoft Excel to automate many common tasks a user would generally conduct manually. Macros save users vast amounts of time. For example, if a user has to click through a list of links and copy and paste the data into the worksheet, a macro can be written to loop through the links, rather than performing the same tasks for each link. Multiple macros can be combined into a single macro, so the user only has to run this master macro instead of all the individual macros.
Things You'll Need
- Microsoft Excel
Create a master macro by clicking on the "View" tab in the toolbar. Click on "Macros" and select "View Macros." Type the name of the master macro, such as "Master," in the "Macro name" box. Click on the "Create" button to launch the Visual Basic editor.
Place the cursor in the second line under the subroutine. For example, if the name of the macro you created is "Master," the first line is "Sub Master()." Under this line, type "Call," followed by the name of the first macro you would like to run. For example, if you created a macro called "GetWebQueries" that loops through a list of URLs, opening each one and copying and pasting the data from a table into a new worksheet, you would type "Call GetWebQueries()."
Press "Enter" to go to the next line. Type "Call," followed by the name of the second macro, such as "Call Format()," which would run the Format macro that formats each worksheet in a specified manner. Save the macro and close the Visual Basic editor.
Run the master macro by clicking on the "View" tab. Click on "Macros" and select "View Macros." Select the master macro and click on the "Run" button. The master macro will run "GetWebQueries" and the "Format" macros in the specified order.