Macro Name: Definition, Rules, and Excel Usage

VBA & macros · Updated November 23, 2026

A macro name is the identifier you assign to a saved sequence of commands or actions in a program like Microsoft Excel, Word, or Google Sheets. In Excel, when you record a macro using the Macro Recorder, you must give it a name before the recording starts, and that name becomes the way you reference, run, and edit the macro later. A macro name is not just a label—it follows strict naming rules, must be unique within its module, and can affect whether your code runs without errors.

What a Macro Name Actually Is

In programming terms, a macro name is a user-defined identifier that points to a stored block of VBA (Visual Basic for Applications) code in Excel or Word, or a custom function in Google Apps Script. When you record a macro, Excel generates VBA code behind the scenes and wraps it in a Sub procedure with the name you provided. For example, if you name a macro FormatReport, the generated code looks like:

Sub FormatReport()
    ' recorded actions
End Sub

That name is what appears in the Macro dialog box (Alt+F8), in the list of macros you can run, and in the VBA editor’s project tree. It is also what you type when you want to call that macro from another macro or from a button.

Rules for Naming a Macro

Excel enforces specific naming conventions for macros. A macro name:

  • Must begin with a letter (A–Z) or an underscore (_). It cannot start with a number or a symbol.
  • Can contain letters, numbers, and underscores, but no spaces, periods, or punctuation like ! or @.
  • Cannot be the same as a cell reference (e.g., R1C1 or A1 is not allowed).
  • Cannot exceed 255 characters.
  • Must be unique within the same module. If you try to record a macro with a name that already exists, Excel asks if you want to replace it.
  • Is case-insensitive for uniqueness: MyMacro and mymacro are considered the same name.

If you violate these rules, Excel shows an error message like “The macro name is not valid” and won’t let you proceed. The same rules apply to procedure names in the VBA editor.

How to Choose a Good Macro Name

While any valid name works technically, a good macro name makes your work easier later. Best practices include:

  • Use descriptive names that indicate what the macro does, such as SortByDate or ClearFormats.
  • Use PascalCase (capitalize each word, no spaces) to improve readability, e.g., GenerateInvoice.
  • Avoid generic names like Macro1 or Test because they become confusing when you have many macros.
  • Prefix related macros with a common word, like Import_Data and Import_Log, to group them in the macro list.
  • Do not use names that conflict with built-in Excel functions or VBA keywords (e.g., Print, Close), as this can cause errors.

Where Macro Names Appear and How They Are Used

Macro names appear in several places in Excel:

  • Macro dialog box (Alt+F8): lists all available macros by name.
  • VBA editor (Alt+F11): the project explorer shows module names, and each procedure’s name is visible in the code window.
  • Assign Macro dialog: when you right-click a button or shape and choose “Assign Macro,” the list shows macro names.
  • Form controls: you can assign a macro to a button by selecting its name from the dropdown.
  • Other macros: you can call a macro by typing its name in VBA, like Call FormatReport or just FormatReport.

In a sentence, you might say: “I named the macro MonthlySummary so I can run it every month.” Or in VBA: RunMacro "MonthlySummary" (though the correct syntax is simply MonthlySummary).

Common Problems with Macro Names

Users often run into these issues:

  • Spaces in names: Typing My Macro gives an error. Use MyMacro or My_Macro.
  • Starting with a number: 2ndReport is invalid; use Report2.
  • Duplicate names: If you record a new macro with the same name as an existing one, Excel prompts to overwrite, which can delete your previous code.
  • Name too long: While 255 characters is allowed, extremely long names are unwieldy; keep under 30 characters for practicality.
  • Case sensitivity: Excel treats names as case-insensitive, so MyMacro and mymacro are the same, which can cause confusion if you think they are different.

Macro Names in Google Sheets and Other Apps

Google Sheets does not use the term “macro name” in the same way. Instead, you create macros with Apps Script, and each function is a named JavaScript function. When you record a macro in Google Sheets, it creates a function like function myFunction() { ... } and you can rename it in the script editor. The naming rules are similar: no spaces, must start with a letter or underscore, and should be descriptive. In Microsoft Word, macros are also VBA procedures, so the same naming rules apply.

Frequently Asked Questions

Can a macro name contain spaces? No. Spaces are not allowed in macro names. Use underscores or capitalize each word instead.

What happens if I use an invalid macro name? Excel displays an error message and does not create the macro. You need to correct the name before proceeding.

Can I rename a macro after recording it? Yes. Open the VBA editor (Alt+F11), find the Sub line with the old name, and edit it. Be careful to update any references to that macro elsewhere.

Is a macro name case-sensitive? No, Excel treats macro names as case-insensitive. MyMacro and mymacro refer to the same procedure.

Can I use a macro name that is the same as a cell reference? No, names like A1 or R1C1 are not allowed because they conflict with Excel’s reference syntax.

Do macro names affect performance? Not significantly. The length or complexity of the name has negligible impact on speed, but a well-named macro is easier to maintain and debug.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.