Run a Macro When you Click a Button in Excel

Add to Favorites

Make a macro run when you click a button in the worksheet in Excel.

This allows you to create a button and put it anywhere in the spreadsheet and then to have a macro run when that button is clicked.

Steps to Have a Macro Run When a Button is Clicked

  1. Create the button.  Go to the Insert tab and click the Shapes button and select the desired button shape.

    Put the button into the spreadsheet and move and size it how you want and even add text to it by clicking it and typing.
  2. Right-click the button and click Assign Macro...

  3. Choose the desired macro from the window that opens and then hit the OK button.
  4. That's it!

    Test it out:

This particular macro simply opens a small window and says "Hi!" but you can assign any macro that you want to this button.

Stop a Macro from Running When a Button is Clicked

You can easily stop the macro from being assigned to the button, meaning that nothing will happen when the button is clicked.

To do this, right-click the button > click Assign Macro > in the window that opens up, remove all of the text under where it says Macro name: and then hit the OK button.

Notes

Make sure that you have the macro already in your workbook before you try to assign it to a button.

In Excel 2007 and later you will have to save the Excel file as an Excel Macro-Enabled Workbook.

Don't forget to download the sample workbook for this tutorial so you can see this feature in action.


Downloadable Files: Excel File

Similar Content on TeachExcel
Run a Macro when a User Does Something in the Worksheet in Excel
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
Run a Macro when a User Does Something in the Workbook in Excel
Tutorial: How to run a macro when a user does something within the Workbook in Excel, such as openi...
Automatically Run a Macro so Many Seconds, Minutes, or Hours After an Excel Workbook has been Opened
Macro: Run a macro after a certain amount of time has passed since the Excel workbook was ope...
Add a Drop Down Menu to a Cell in Excel - Data Validation Macro
Macro: Add a drop down menu or list to a cell in Excel with this free Excel macro. This is a...
Stop Excel Events from Triggering when Running a Macro
Tutorial: Create a macro that will run without triggering events, such as the Change event, or Activ...
Disable Calculation of Cells when Running a Macro in Excel
Tutorial: How to stop formulas and functions from updating in Excel when running a macro. This can s...