Excel Tutorial Topics

Other Tools

Assigning Macro to Button in Excel

Do you want a button to run a VBA macro in excel ?
Remembering shortcuts for each and every macros is not easy so you probably required buttons with label to recognize macros and easily run them. Today we will learn how we can assign a VBA macro to a button in worksheet. We will learn it in just three easy steps here. We are considering excel 2007 for menu options and examples.

Step# 1: Go to Insert menu and click on the shapes then choose Rectangle shape and give it name by edit text in mouse right click option.

Excel Button

Step# 2: Now record a simple macro to test if you have not any macro recorded. You can also open the VBA console window by pressing Alt + F11 and paste the below macro code.

Sub Macro1()

MsgBox “You have just hit the button.”

End Sub

Step# 3: Now right click on the rectangle button and click Assign Macro. Select the macro to assign from the list and click OK.

Excel Macro Assign

Once macro is assigned to button, cursor will change to hand on hovering the button. If you want format button, move button or assign another macro to the button, you can do it from the options available on mouse right click.

Where you can use it?

You can best use it as a calculator button like you must have seen simple accounting application which has excel cells for input and submit button to runs a macro that calculate and give you output.