After creating or recording a Macro, the next step is to run the Macro. Running a macro tells Excel to execute the instructions stored inside that macro.
Running a macro means executing the VBA instructions stored inside the macro.
When you run a macro, Excel performs the actions defined in the macro automatically.
The main purpose of running a macro is to automate a task that would otherwise require manual steps.
For example, a macro can format a report, calculate values, or process data automatically.
First, open the Excel workbook that contains the macro you want to run.
For practice, you can use the macro created in the previous lesson.
Click the Developer tab on the Excel Ribbon.
The Developer Tab provides several tools for working with macros, including the Macros command.
In the Developer Tab, click the Macros button.
Excel will open the Macro dialog box.
The Macro dialog box displays macros that are available to run.
You can select a macro from the list and then choose an available action such as Run or Edit.
Select the macro that you want to execute.
For example, if you created a macro named:
FormatStudentData
select FormatStudentData from the list.
After selecting the macro, click the Run button.
Excel will execute the instructions contained in the selected macro.
After running the macro, observe the worksheet.
The actions recorded or programmed inside the macro should be performed automatically.
For example, formatting may be applied to the selected cells.
A recorded macro can be run in the same way as other macros.
For example, if you previously recorded a macro that makes headings bold, running it can apply that formatting again.
One common method of running a macro is:
This method provides a clear way to view and select available macros.
Excel also provides access to the Macro dialog through the View tab.
You can use the Macros command available under the View tab to open the Macro dialog and run a macro.
A macro can be assigned a keyboard shortcut when the macro is created or configured.
After assigning a shortcut, you can use that shortcut to run the macro more quickly.
A macro can also be assigned to a worksheet button.
When the user clicks the button, the assigned macro runs.
This is useful when creating user-friendly Excel applications.
A macro can also be assigned to a shape inserted into an Excel worksheet.
For example, a shape labeled Generate Report can be connected to a macro that creates or formats a report.
A macro can generally be run multiple times when the same automation is required.
For example, if a macro formats a report, you can run it whenever the same formatting operation is needed.
When a macro runs, Excel executes the VBA statements contained in the macro's procedure.
The exact result depends on what instructions were recorded or written in the VBA code.
Suppose you created a macro that makes the heading of a student marksheet bold.
When you run the macro, Excel executes the formatting instructions and the heading becomes bold.
Sub FormatStudentData()
Range("A1:B1").Select
Selection.Font.Bold = True
End Sub
Some recorded macros operate on the workbook, worksheet, or cells that were involved when the macro was created.
Therefore, you should understand which workbook and worksheet the macro is designed to work with.
Excel security settings can affect whether a macro is allowed to run.
If macros are blocked, you may see a security notification when opening a macro-enabled workbook.
Only enable macros when the workbook and its code are trusted.
If you want to keep VBA macros in an Excel workbook, the workbook should be saved in a macro-enabled format such as .xlsm.
This allows the workbook to store VBA macro code.
When you run a macro, Excel executes its VBA instructions in sequence.
Depending on the macro, it may:
A macro can be edited in the VBA Editor.
After making changes to the VBA code, you can return to Excel and run the macro to test the updated behavior.
It is important to test a macro after creating or editing it.
Check whether the macro performs the intended actions and produces the expected result.
Use sample data while learning and testing.
One common reason is that macros are disabled by Excel's security settings.
Other possibilities include an incorrect workbook, an unavailable macro, or an error in the VBA code.
Suppose you recorded a macro named:
FormatStudentData
The macro makes the heading bold and applies borders to a student marks table.
Open the Macros dialog, select FormatStudentData, and click Run. Excel performs the recorded formatting operations.
| Method | Basic Use |
|---|---|
| Developer → Macros | Select and run a macro. |
| View → Macros | Open the Macro dialog. |
| Keyboard Shortcut | Quickly execute an assigned macro. |
| Worksheet Button | Run a macro by clicking a button. |
| Shape | Run a macro from an assigned shape. |
A simple macro execution workflow is:
Running a macro means executing the VBA instructions stored inside the macro. Excel provides several ways to run a macro, including the Developer Tab, View Tab, keyboard shortcuts, worksheet buttons, and shapes.
The most basic method for beginners is to open the Macro dialog, select the required macro, and click Run.
Always test your macros carefully and only enable macros from workbooks that you trust.
Question: What should you click after selecting a macro in the Macro dialog to execute it?