Run a Macro When you Click a Button in Excel

Add to Favorites
Author: | Edits: don

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.
    74efcb5003afee7df80f4c2383d87199.jpg
    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.
    b8685e8d9b8cf0055d41e12b792490ed.jpg
  2. Right-click the button and click Assign Macro...
    cbc415e59c5c07126bd891cb37942455.jpg
  3. Choose the desired macro from the window that opens and then hit the OK button.
    1939c57be07e66079471c46f5bdbe767.png
  4. That's it!
    a720cbb5d24355a9ff9925531ffaafc6.jpg
    Test it out:
    14bf9dc8e2e55f04305bfe541c7d2fad.jpg

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

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

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...
Excel Data Validation - Limit What a User Can Enter into a Cell
Tutorial: Data Validation is a tool in Excel that you can use to limit what a user can enter into 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...
Tutorial Details
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course