Your Guide to How To Add a Macro In Excel

What You Get:

Free Guide

Free, helpful information about Productivity & Office Tools and related How To Add a Macro In Excel topics.

Helpful Information

Get clear and easy-to-understand details about How To Add a Macro In Excel topics and resources.

Personalized Offers

Answer a few optional questions to receive offers or information related to Productivity & Office Tools. The survey is optional and not required to access your free guide.

How to Add a Macro in Excel: A Complete Guide

Macros are one of Excel's most powerful — and most underused — features. If you find yourself repeating the same sequence of steps over and over in a spreadsheet, a macro can collapse all of that into a single click. Here's how they work, how to add one, and what determines whether your approach will suit your situation.

What Is a Macro in Excel?

A macro is a recorded set of actions or a written script that Excel can replay on demand. Instead of manually formatting a report, sorting data, or running calculations every week, you record or write the macro once, then run it whenever you need it.

Macros in Excel are built on VBA (Visual Basic for Applications) — a programming language embedded in Microsoft Office. You don't need to know VBA to create basic macros, but understanding it opens up far more powerful possibilities.

Two Ways to Add a Macro in Excel

1. Record a Macro (No Coding Required)

The macro recorder is the fastest entry point. Excel watches what you do and converts your actions into VBA code automatically.

How to record a macro:

  1. Go to the View tab on the ribbon
  2. Click MacrosRecord Macro
  3. Give your macro a name (no spaces — use underscores, e.g., Format_Report)
  4. Optionally assign a shortcut key (e.g., Ctrl+Shift+F)
  5. Choose where to store it (more on this below)
  6. Click OK, then perform your actions in Excel
  7. When finished, go back to ViewMacrosStop Recording

Your macro is now saved and ready to run.

2. Write a Macro in the VBA Editor

For anything beyond simple recorded steps — conditional logic, loops, dynamic ranges, error handling — you'll write VBA directly.

How to open the VBA editor:

  1. Press Alt + F11 (Windows) or Option + F11 (Mac)
  2. In the Project pane, right-click your workbook and select Insert → Module
  3. Type or paste your VBA code in the module window
  4. Close the editor and run the macro via View → Macros → View Macros

A basic VBA macro looks like this: