• Work with macros Video
  • Edit a macro Video
  • Save your macro Video
  • Assign a button to a macro Video

assign a macro

Assign a button to a macro

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

In this final video, we’ll hook the macro up with a button and make it available in two places: In a custom group on the Developer tab, and on the Quick Access Toolbar.

Create or delete a macro

Edit a macro

Assign a macro to a button

Create and save all your macros in a single workbook

In this final video, we'll hook the macro up with a button and make it available in two places.

In a custom group on the ribbon that I'll create on the DEVELOPER tab, I'll call My Macros , and up here on the Quick Access Toolbar .

First, I'll create a custom group for the DEVELOPER tab.

I click the FILE tab, Options , Customize Ribbon , and then I make sure Developer is checked.

I click New Group and here is our new group.

I click Rename , and call it My Macros .

Now, let's find the macro and add it to this custom group.

I go over here and choose commands from Macros .

I select the "FillDaysRelativeR" macro that's stored in my 'Personal Workbook' and click Add .

Here it is, it's now in the group and I want to rename it.

I click Rename and call this "Fill Days".

You can have spaces in display names.

While I am at it, I'll replace the cryptic icon with this icon that looks a little bit like a calendar.

I click OK , click OK again and here's my macro button in my custom My Macro group.

I click it and it works.

Now I'll show you how to add the same macro to the Quick Access Toolbar , so it'll be up here next to Redo .

Click FILE and Options , and this time, click Quick Access Toolbar .

Again, I choose commands from Macros, and here's the macro in my personal workbook. Click Add .

To rename it, click Modify . Call it "Fill Days" and choose the same grid icon.

I click OK , and click OK again.

Now here it is, up on the Quick Access Toolbar .

I click it, and of course, it works great again.

Now you have a pretty good idea about how to implement macros in Excel.

Of course, there's always more to learn.

So check out the course summary at the end, and best of all, explore Excel 2013 on your own.

Facebook

Need more help?

Expand your skills.

EXPLORE TRAINING >

Get new features first

JOIN MICROSOFT 365 INSIDERS >

Was this information helpful?

Thank you for your feedback.

assign a macro

assign a macro

How to Assign a Macro to a Button in Excel

March 07, 2018

Running macros in your worksheet is a tremendous help. You can automate so many things with VBA that there have been countless books written on the topic. However, it’s not always so simple to run a macro. Your users may not know how to run a macro and you want to make it easy for your users to get their work done. Wouldn’t it be great to have a button on your worksheet and you can tell your users “Just click on this and such-and-such will be done automatically”?

That’s what this post is all about. Let’s get started.

Assign a Macro to a Simple Button

To begin, you’ll need to have the Developer Tab enabled. Click here for more info on that.

After you have the developer tab enabled, open up the Visual Basic Editor, add a new module and let’s add this simple code snippet in there:

This will be our simple macro to run when we click on our button.

Since we have the Developer Tab enabled, we can create a button and assign it to a macro:

Here’s an animated gif to help illustrate the point:

Does this article help you? If so, please consider supporting me with a coffee ☕️

Buy Me a Coffee at ko-fi.com

Assign a Macro to a Shape

Now that we have the main idea down, let’s add some style to our worksheet. Using the Button from the Developer Tab is not the only way to run a macro from a button. You can also use Excel Shapes!

To achieve this, we follow a similar procedure from before, but the difference is where we get our button from. Here are the steps to assign a macro to a shape in your worksheet:

Here’s an animated gif to show more detail:

Changing the Assigned Macro

To change the macro assigned to the button, simply right-click on it, then choose Assign Macro. From there, you can select a new macro to use.

Deleting the Button

To delete the button, you need to get it back into Edit Mode. To do this, right-click on the button. When you do this, the context menu will show up. You can click back to the worksheet (but DON’T double-click!) and you will still be in Edit Mode. From here, you can hit the Delete key on your keyboard and it will remove the button.

TrumpExcel Logo - Online Excel Tips & Tricks

How to Assign a Macro to a Button in Excel (Easy Guide)

While there are many different ways to run a macro in Excel, none of those methods can be as easy and user-friendly as clicking on a button.

And for that to work, you need to assign a macro to a button first.

In this tutorial, I will show you a couple of ways to insert a button in  Excel and then assign a macro to that button (or shape). Once done, as soon as a user clicks on the button, the macro VBA code would be executed.

For the purpose of this tutorial, I will be using the below VBA macro code (which simply selects cell A1 in the active sheet and enters the text “Good Morning” in it and colors it red).

The above VBA code is placed in a regular module in the VB Editor

Adding VBA Macro to a regular module

Now let’s dive right in and see how you can assign this macro to a button or shape in Excel!

This Tutorial Covers:

Insert a Shape and Assign Macro to that Shape

While there are dedicated buttons that you can insert in the worksheet and then assign the macro to it, I will first cover how to assign a macro to a shape .

I personally love this method and prefer it over the rest two methods covered later. You can easily insert a shape (square or rectangle) and can make it look like a button.

And since it’s a shape, you can easily format it to look perfect with your existing formatting or brand colors.

Below are the steps to insert a shape in Excel:

Click the Insert Tab

After you have done the above steps, you will have a rectangle shape in the worksheet, and now we will assign a macro to this shape.

Now let’s see how to assign a macro to this shape.

Click on Assign Macro

Select the macro from the list

That’s it!

The selected macro has now been assigned to the shape.

Now when you hover the cursor over the shape, it will show the hand icon. which indicates that now this shape has become clickable.

The button becomes clickable

And now if you click on the shape, it will run the assigned macro .

You can type any text within the shape to make it more intuitive (such as ‘Click here to run the macro’). To do this. right-click on the shape and then click on Edit Text. Now you can type within the text box shape.

Edit Text option to add text to the shape

Note that you won’t be able to click and run the macro when the shape has been selected (i.e., you see a border around the shape that appears when you select it), To make it clickable, hit the Escape key or click anywhere in the worksheet.

Also, when you have assigned the macro to the shape already, you will not be able to select it by using the left mouse key (as it has become clickable and left-click would now execute the macro). In that case, select the shape, hold the control key and then press the left key.

Keeping Shape Visible When you Hide/Resize Rows/Columns

In Excel. when you insert a shape, it sits over the cells – like a chart/object.

This also has a drawback that when you resize or hide rows/columns that have the shape over it, the shape also follows suit.

In the below example, the shape gets hidden when I hide the column on which it’s placed.

If you don’t want this to happen, follow the below steps:

Right click and then click on Format Shape

Click on Don't move or size with cells

Now, when you resize rows/columns or hide these, the shape would stay in its place.

Assign a Macro to Form Control Button

If you’re not too concerned with the formatting of the button and are ok with regular gray buttons, you can quickly insert it from form control (or ActiveX control as shown next) and then assign a macro to it.

For this to work, you will need to have the Developer tab in your ribbon. If you don’t have it, here is a detailed step-by-step tutorial on getting the developer tab in the Excel ribbon .

Once you have the developer tab visible, you can use the below steps to quickly insert a button and assign a macro to it:

Click the Developer tab

The above steps would insert a button that has the specified macro assigned to it.

By default, it would be a small button with text such as ‘Button’ written on it. You can change the text to whatever you want and can also change the shape of the button (by dragging the edges).

Since this is an object that is placed over the worksheet (just like shapes/charts), you can drag and place it anywhere in the worksheet.

One drawback of using the Form Control button is that you don’t have much control over the formatting. For example, you can not change the color from gray to something else.

Although there is a little bit of formatting that you can do with a Form control button, it’s nowhere close to what you can do with shapes.

You get these button formatting options when you right-click on the button and then click on Format Control.

Right click on the button and then click on format control

This will open the Format Control dialog box where you can change the font type/color, size, alignment, etc.

Formatting options for a form control button

One good thing about this button is that it doesn’t hide or resize when you hide the rows/columns or resize them. It would, however, move in case you change the height or width or the row/column over which the button is placed.

In case you don’t want the button to stay in its place, you can change the setting by following the below steps:

Select do not move or size with cells options for the form control button

Assign a Macro to an ActiveX Control Button

Apart from the Form Control button, there is also an ActiveX control button to which you can assign a macro.

In most cases, you won’t need to use the ActiveX control button, and I recommend you use it only when you completely understand what it is and you know what you’re doing.

This also, sometimes, make ActiveX a bit glitchy and unpredictable. So, while I cover it in this tutorial, I don’t recommend using ActiveX button and assign a macro to it.

To insert an ActiveX button and then assign a macro to it, follow the below steps:

Click on ActiveX Control Command Button option in the developer tab

With ActiveX control, you get a lot more flexibility with a single button. For example, you can specify one macro to be run when you simply click on the button once and another macro when you double-click or even another one when you use the up/down arrow key.

Again, not something you need to be using in your regular work.

Hope you found this tutorial useful. If you’re interested in learning VBA, you can check out more in-depth Excel VBA tutorials here .

You may also like the following Excel tutorials:

Excel Ebook Subscribe

FREE EXCEL BOOK

Get 51 Excel Tips Ebook to skyrocket your productivity and get work done faster

1 thought on “how to assign a macro to a button in excel (easy guide)”.

Following the procedure here, I cannot assign a Macros from an *.xlam workbook (addin). Is there a way to do this? thx

Comments are closed.

BEST EXCEL TUTORIALS

Best Excel Shortcuts

Conditional Formatting

Creating a Pivot Table

Excel Tables

INDEX- MATCH Combo

Creating a Drop Down List

Recording a Macro

© TrumpExcel.com – Free Online Excel Training

DMCA.com Protection Status

Privacy Policy  | Sitemap

AutomateExcel Logo

Add a Button and Assign a Macro in Excel

Excel buttons.

In Excel, Buttons are used to call Macros. This tutorial will cover how to create Excel buttons, assign Macros to them, adjust their properties, and more.

By default, Excel macros are accessible in a list via the “Macros” button on the View ribbon.

assign a macro

Often though, you’ll want to provide easy access to a particular macro directly on your worksheet.  This can be achieved using a Button control.

A Button control looks like a Microsoft Windows button, and runs a macro when clicked.  It’s a much handier way to access your most commonly used macros, and is an easy way to expose custom functionality to other users of your workbook.

Run a Macro From a Button

To run a Macro from a button in Excel, simply click the button:

The Excel Developer Tab

Buttons are accessible via the Developer Tab.

assign a macro

Unfortunately, Excel hides the Developer tab by default.  If you don’t see the Developer Ribbon, follow these steps:

Excel File Button

excel enable developer ribbon

Add a Macro Button

In Excel, select the Developer tab, then click on the “ Insert ” dropdown in the Controls section.  There are several types of controls divided into two sections, “Form Controls” and “ActiveX Controls”.

excel insert button

For now, just click on the Button control under “ Form Controls ”.  Next, move the mouse anywhere over the worksheet surface, then hold left-click and drag the mouse to draw the outline of a rectangle.  When you release left-click, a new dialog will appear titled “ Assign Macro ”.

Assigning a Macro to a Button

assign a macro

Here you can assign an existing Macro to the button, record a new macro, create a new macro from scratch using VBA, or click “Cancel” and return to your button later.

Assign Existing Macro to a Button

To assign an existing Macro, you simply select the macro’s name in the list, then click OK.

Edit an Existing Macro Before Assigning to a Button

To edit a macro before assigning it to the button, select the macro’s name in the list and click the “Edit” button (the “New” button text changes to “Edit”).

assign a macro

Record a Macro and Assign to Button

assign a macro

Write VBA Procedure and Assign to Button

To write a new macro for the button, type a new name for your macro in the textbox at the top of the dialog, then click “New”.  Excel will bring up the VB Editor, in which you’ll see a new empty macro procedure with the name you entered.  This procedure will be stored in a new module, visible in the Project window.

assign a macro

Change Macro Assigned to Button

To change the Macro that’s assigned to a button, simply right-click the button and select Assign Macro :

assign a macro

Here you can see the assigned Macro and make any desired changes.

assign a macro

How to Adjust Button Properties in Excel

Move or resize excel button.

After you’ve placed a button, you can easily move or resize it.  To perform any of these actions, right-click on the button. Then you can left-click and drag the button to your desired location or resize it.

excel move and resize buttons

Rename Button

With the button selected, left-click on the button text to edit.

To add multiple lines, simple press the ENTER key.

macro new text

Format Button

To format other button properties, Right-Click > Format Control

assign a macro

Here you can adjust font sizes, and many other button properties:

excel button properties font

Of particular note is the “Properties” tab, which changes how the button behaves as surrounding rows and columns are inserted, deleted, resized, or hidden/unhidden.

excel format button properties

Assign a Macro to a Shape

Besides buttons, macros can assigned to other objects like Pictures, Textboxes, and Shapes.  With a Picture or Shape, you can make a button that looks any way you like.  Excel includes a wide variety of customizable Shapes including polygons, arrows, banners, and more that may be better suited to your worksheet than a regular button control.

Shapes are accessed from the Insert tab:

excel insert shape

Select the shape you want from the Shape dropdown, draw it onto your worksheet as you would a button control, then right-click it and select “Assign Macro…” from the pop-up dialog.  The options are the same as assigning a macro to a button.

assign macro to a shape

Assign a Macro to a Hyperlink

Macros can also be assigned to hyperlinks by using VBA Events . Events are procedures that are triggered when certain actions are performed:

Events require knowledge of VBA.  To learn more about events, visit our VBA Tutorial .

assign a macro

Ultimate VBA Add-in

Offer expires soon!

Sale Ends Friday at Midnight

VBA (Macros) Code Examples Add-in

Trustspot Reviews

#1 Excel tutorial on the net

Developer Tab | Command Button | Assign a Macro | Visual Basic Editor

With Excel VBA you can automate tasks in Excel by writing so called macros. In this chapter, learn how to create a simple macro which will be executed after clicking on a command button. First, turn on the Developer tab.

Developer Tab

To turn on the Developer tab, execute the following steps.

1. Right click anywhere on the ribbon, and then click Customize the Ribbon.

Customize the Ribbon in Excel

2. Under Customize the Ribbon, on the right side of the dialog box, select Main tabs (if necessary).

3. Check the Developer check box.

Turn on the Developer Tab

4. Click OK.

5. You can find the Developer tab next to the View tab.

Developer Tab

Command Button

To place a command button on your worksheet, execute the following steps.

1. On the Developer tab , click Insert.

2. In the ActiveX Controls group, click Command Button.

Insert a command button control

3. Drag a command button on your worksheet.

Assign a Macro

To assign a macro (one or more code lines) to the command button, execute the following steps.

1. Right click CommandButton1 (make sure Design Mode is selected).

2. Click View Code.

View Code

The Visual Basic Editor appears.

3. Place your cursor between Private Sub CommandButton1_Click() and End Sub.

4. Add the code line shown below.

Add Code Line

Note: the window on the left with the names Sheet1 (Sheet1) and ThisWorkbook is called the Project Explorer. If the Project Explorer is not visible, click View, Project Explorer. If the Code window for Sheet1 is not visible, click Sheet1 (Sheet1). You can ignore the Option Explicit statement for now.

5. Close the Visual Basic Editor.

6. Click the command button on the sheet (make sure Design Mode is deselected).

Excel Macro Result

Congratulations. You've just created a macro in Excel!

Visual Basic Editor

To open the Visual Basic Editor, on the Developer tab , click Visual Basic.

Open the Visual Basic Editor

Learn more, it's easy

Download Excel File

Follow Excel Easy

Excel Easy on Facebook

Become an Excel Pro

Next Chapter

Create a Macro • © 2010-2023 Excel is Awesome, we'll show you: Introduction • Basics • Functions • Data Analysis • VBA

IMAGES

  1. Assign a macro to a shape in Excel

    assign a macro

  2. Macros

    assign a macro

  3. How To: Assign a Macro to a Button or Shape

    assign a macro

  4. How to Assign a Macro to a Button in Excel

    assign a macro

  5. Google Sheets

    assign a macro

  6. Assign a macro to a command button in Excel

    assign a macro

VIDEO

  1. Fanuc Robot || Setting program as macro and assign keys to macro program

  2. How to Customize Buttons

  3. How to Create Macro in Excel #shorts

  4. MACROS

  5. What are Macros?

  6. Macro Advance Excel

COMMENTS

  1. Assign a macro to a Form or a Control button

    Add a button (Form control) · On the Developer tab, in the Controls group, click Insert, and then under Form Controls, click Button · Click the worksheet location

  2. Assign a macro to a button

    Click File > Options > Quick Access Toolbar. · In the Choose commands from list, click Macros. · Select the macro you want to assign a button to. · Click Add to

  3. Video: Assign a button to a macro

    Assign a button to a macro ... In this final video, we'll hook the macro up with a button and make it available in two places: In a custom group on the Developer

  4. How to Assign a Macro to a Button in Excel

    Assign a Macro to a Simple Button · In the Developer Tab of the ribbon, simply click on Button (in Windows, click on Insert, and then under Form

  5. How to Create a Macro Button in Excel

    In this video, I demonstrate how to assign a macro to a button in Excel. The video runs you through how to create a simple navigation button

  6. How to Assign a Macro to a Button in Excel 365

    In this micro-lesson you will:- Click on the desired location for the button or draw a box with the mouse- Select the desired Macro from the

  7. Assign a Macro to a Button, Check box, or any object in Microsoft Excel

    http://www.TeachMsOffice.comThis video tutorial shows you how to attach or assign a macro in excel to a button, check box, or any other

  8. How to Assign a Macro to a Button in Excel (Easy Guide)

    Insert a Shape and Assign Macro to that Shape · Right-click on the shape on which you want to assign the macro · In the menu options that appear

  9. Add a Button and Assign a Macro in Excel

    To change the Macro that's assigned to a button, simply right-click the button and select Assign Macro: Here you can see the assigned Macro and make any desired

  10. How to Create a Macro in Excel (Easy VBA)

    Create a Macro · 1. On the Developer tab, click Insert. · 2. In the ActiveX Controls group, click Command Button. Insert a command button control · 3. Drag a