Excel Add Macro Button

“excel add macro button” comes up constantly, so this page leads with the exact answer, and only then explains the detail. Everything works in Excel on Windows and Mac and maps almost one-to-one to Google Sheets. Copy the answer above and get back to work, or read on to turn a one-off fix into something you never have to look up again.

Exact answer

In Excel: Developer ▸ Insert ▸ Button (Form Control), drag out the rectangle on the sheet, and pick your macro from the Assign Macro dialog that opens.

VBA macro: Add a Button That Runs a Macro

Sub AddMacroButton()
    Dim ws As Worksheet
    Dim btn As Button
    Set ws = ActiveSheet
    Set btn = ws.Buttons.Add(ws.Range("F2").Left, ws.Range("F2").Top, 130, 28)
    btn.OnAction = "SayHello"
    btn.Caption = "Run SayHello"
End Sub

Sub SayHello()
    MsgBox "The button ran this macro.", vbInformation
End Sub

Buttons.Add takes Left, Top, Width and Height in points, so anchoring to a cell's .Left/.Top drops the button neatly over F2. OnAction holds the macro NAME as text — a typo there fails silently at click time, not at compile time.

How to run this macro

  1. Press Alt + F11 to open the VBA editor.
  2. Insert > Module.
  3. Paste the code above.
  4. Press F5, or close the editor and run it from Developer > Macros.
  5. Save the file as .xlsm so the macro is kept.
Annotated stepsExcel
1

Turn on the Developer tab if it is not visible: File ▸ Options ▸ Customize Ribbon, tick Developer, click OK.

2

Choose Developer ▸ Insert and pick Button under Form Controls — the top-left icon, not the ActiveX section below it.

3

Drag out a rectangle where you want the button to sit; the Assign Macro dialog opens automatically.

4

Select the macro name and click OK.

5

Right-click the button and choose Edit Text to relabel it — never left-click, which runs the macro — then click any cell to leave edit mode and test it.

Ctrl+CthenCtrl+Shift+V+Cthen+Ctrl+VPaste values · WindowsMac

What this does

A button is the difference between a macro only its author can run and one the whole team can. Excel offers three ways to place one. The Form Control button is the right default: Developer ▸ Insert ▸ Button, drag a rectangle, and Excel immediately opens Assign Macro so you can pick the procedure. It is lightweight, survives being copied between workbooks, and works on Mac. The ActiveX command button in the same menu looks more configurable but is Windows-only and notorious for corrupting itself, so avoid it unless you need a property the Form Control lacks. The third option skips controls entirely: draw any shape via Insert ▸ Shapes, right-click it, and choose Assign Macro — you get a button that can look like anything, which is how most polished dashboards do it. Most people learn this as a sequence of clicks and forget it by next week; learning it as a pattern instead is what lets you apply it to the next, slightly different version of the problem without starting from scratch. That is the difference this page is trying to make. For “excel add macro button”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected cells change, and only then apply the same setup to the full sheet. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That is what makes a workflow that saves repeating the same clicks every week useful in real work: repeatable, auditable, and not dependent on memory or luck.

A worked example

Your workbook has a macro named RefreshReport and colleagues keep asking where to find it. Open the Developer tab (File ▸ Options ▸ Customize Ribbon ▸ tick Developer if it is missing), choose Insert ▸ Button under Form Controls, and drag a rectangle beside the data. The Assign Macro dialog opens; select RefreshReport and click OK. To relabel it, right-click the button and choose Edit Text — a left-click just runs the macro, so right-click is the instruction that works whether or not the control still happens to be selected. Now anyone can run the macro without ever opening the editor. To do the same in code rather than by hand, run Sub AddMacroButton() — it places a button over F2 and points its OnAction at SayHello, which is useful when a macro has to build its own interface across many sheets. A macro nobody can find is a macro nobody uses. Putting a labelled button on the sheet removes the Alt + F11 barrier entirely, which is what makes an automation shareable with people who will never open the editor. A practical tip before you scale it up: build it once on a small block of test data, confirm the number against the tool on this page, and only then point it at your real sheet. That one habit catches almost every mistake while it is still cheap to fix, long before a wrong figure reaches a report or a colleague.

In Google Sheets

If you are in Google Sheets rather than Excel, the good news is that the formula shown here is identical and the workflow barely changes — menus sit across the top instead of in a ribbon, and a few function names differ slightly, but anything you build here moves across with little or no rework. Keep this page bookmarked for the next time the same question comes up. Better still, rebuild the example once in your own sheet — doing it yourself, with the tool above to check against, is what turns a copied formula into a technique you own. If you take one thing from this page on “excel add macro button”, make it the habit rather than the keystrokes: set the problem up with labelled inputs, reference those cells, and let Excel do the recomputing. Bookmark the page for the syntax, but do the example once in a blank sheet and check it against the tool above — five minutes of hands-on practice fixes the method in memory far better than re-reading, and it surfaces the small snags while they are still harmless. After that the technique is genuinely yours: faster than searching for it again, and reliable enough to drop into work that other people depend on.

Common mistakes

  • Picking the ActiveX command button instead of the Form Control. ActiveX controls are Windows-only, break on Mac, and are a well-known source of "Cannot insert object" corruption after the file has moved between machines.
  • Left-clicking the finished button to move or edit it, which just runs the macro. Right-click (or Ctrl + click on Mac) selects it for editing instead.
  • Assuming a button carries its macro with it. Copying a button into another workbook copies only the macro NAME held in OnAction; if no procedure of that name exists there, the click fails with "cannot be found".
  • Letting the button float over data. Right-click ▸ Format Control ▸ Properties ▸ "Don't move or size with cells" keeps it in place when rows are inserted or columns resized.

Frequently asked questions

How do I edit a button without triggering the macro?

Right-click it (Ctrl + click on Mac). That selects the control and opens the context menu with Edit Text, Assign Macro and Format Control, without running anything.

Can I use a picture or a shape instead of a grey button?

Yes, and most dashboards do. Insert ▸ Shapes or Insert ▸ Pictures, then right-click the object and choose Assign Macro. It behaves exactly like a Form Control button.

My button says the macro cannot be found — why?

OnAction stores the macro name as plain text, so renaming the Sub, deleting its module, or copying the button to a workbook without that procedure all break the link. Right-click ▸ Assign Macro and re-select it.

Can one button run several macros?

Indirectly. Point the button at a single wrapper Sub that calls the others in order — that also makes the sequence easy to change later without touching the button.

Other ways people ask this

This is also commonly searched as “how to add a macro button in excel” and “add a macro button in excel”. They describe the identical operation, so you are in the right place no matter how you phrased it.

Why do people search for this in so many different ways?

Because the same task has many names. “how to add a macro button in excel”, “add a macro button in excel” all point at the one operation explained on this page, which is why they all lead here.