Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Assign a Macro to a Button

In Earlier session we saw how to add a button to the top menu of the Excel file (How to Get Access to the ToolBar)

Excel-VBA-MACRO-Assign a Macro to a button — 1

Excel-VBA-MACRO-Assign a Macro to a button — 1

In the Code window we have created two sub routines

Sub Assign_Macro1 ()

….Some Code….

End Sub

Sub Assign_Macro2 ()

….Some Code….

End Sub

Excel-VBA-MACRO -Assign a macro to a button -1

Excel-VBA-MACRO -Assign a macro to a button -2

Now you can assign it to button .

To get the Button on the Excel, Click and Hold the Button icon in the Top menu of the Excel and Then Click + Hold + drag  in Excel Sheet (WorkSheet) to give it proper size.

For the very first time when you create a button another window will prompt automatically to assign Macro to that button

Excel-VBA-MACRO-Assign a Macro to a button— 3

Excel-VBA-MACRO-Assign a Macro to a button— 3

You can click cancel and Assign the Macro later to this Button

you can see that Sheet1.Assign_Macro1 and Sheet1.Assign_Macro2 macro’s are displayed, you can select any of these and click OK. Now when next time when you click the button the select sub routine will be called.

You can change the Assigned Macro or re-size the button or Edit the Text on the button or any other kind of formatting by right click on the button and select the appropriate option from the menu.

Excel-VBA-MACRO-Assign a Macro to a button-4

Excel-VBA-MACRO-Assign a Macro to a button-4

 

You may also like...

2 Responses

  1. Vishal Tulsiyan says:

    i created the buttons. however, in my code sheet (alt+f11) i am still not able to see any new sub routines created.

    on the right side (code window) i can just see this:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub

    • sumitjain says:

      Hello Vishal,

      Sorry for one offline question, r u the one who studied from chennai and stayed at medavakkam, if not please ignore.

      Answer to your question: First you have to create a sub routine in the code window and then assign it to button , not the other way around.
      please let me know if u still not able to resolve it , it will give the detail description then 🙂

      Thanks
      Sumit

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: