Subscribe for Weekly Tutorials
BONUS: subscribe now to download our Top Tutorials Ebook!
Run a Macro When you Click a Button in Excel
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
- 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. - Right-click the button and click Assign Macro...
- Choose the desired macro from the window that opens and then hit the OK button.
- 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.
Question? Ask it in our Excel Forum
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
Tutorial: How to run a macro when a user does something within the Workbook in Excel, such as openi...
Macro: Run a macro after a certain amount of time has passed since the Excel workbook was ope...
Tutorial: Data Validation is a tool in Excel that you can use to limit what a user can enter into a...
Tutorial: Create a macro that will run without triggering events, such as the Change event, or Activ...
Tutorial: How to stop formulas and functions from updating in Excel when running a macro. This can s...