Skip to content
Related Articles

Related Articles

How to Run a Macro in Excel?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 20 Jan, 2022

You can record a macro in excel or write from scratch in VB Editor.  Excel provides different options to run a macro.  In this article, we explore four different ways to run a macro in an excel application.

The below macro will write text “Geeks for Geeks” in cell B5.

Sub updateText()

ActiveSheet.Range("B5").Value = "Geeks for Geeks"

End Sub

Approach 1: Run a macro in the Macro Dialog box

Follow the below steps to run a macro in the Macro dialog box:

Step 1: Go to View >> Macros >> View Macros – to popup Macro dialog box [keyboard shortcut – Alt+F8].

Step 2: Select Macro from the list (eg. updateText) and Press “Run”.

Output:

Approach 2: Run a Macro in VBE

Follow the below steps to run a macro in VBE:

Step 1: Open Excel.

Step 2: Go to Developer>> Visual Basic – to open VBE [ keyboard shortcut – Alt+F11 ].

Step 3: Select anywhere in the macro code and Click the “Run button” (Green Arrow) or Press F5.

Approach 3: Assign a Keyboard Shortcut to Execute a Macro

Follow the below steps to assign a keyboard shortcut to execute a Macro:

Step 1: Go to View >> Macros >> View Macros – to popup Macro dialog box [keyboard shortcut – Alt+F8].

Step 2: Select Macro from list (eg. updateText) and Press “Options” ,to popup Macro Options

Step 3: Give any specific text in Shortcut key input [eg. Ctrl+p] and Press “OK”. Close Macro list.

Step 4: Just press your Shortcut key eg. Ctrl+p, to execute the macro.

Approach 4: Add a Shape in Excel to Execute a Macro

Follow the below steps to add a shape in excel to execute a macro:

Step 1: Add a shape “Run Macro”.

Step 2: Right-click Shape and Press “Assign Macro” , to popup the Assign Macro dialog box

Step 3: Select “updateText” Macro and Press “OK”.

Step 4: Just click the shape “Run Macro” in your excel file to run the macro.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!