Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Understanding Macros.

Understanding Macros

Written by Allen Wyatt (last updated October 18, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


4

A macro is similar to a computer program. It consists of a series of instructions that the computer follows in a sequence you specify. The macro is given a name that is used to run the instructions it contains. Excel provides two general ways to create a macro. The first (and easiest) method is to record a macro using the macro recorder. The other method is to write a macro from scratch using the VBA Editor. While writing from scratch is perfectly acceptable, it is often a good idea, especially for smaller macros, to record the basic steps you want performed and then edit the recorded macro to create the final instructions.

Anything you do in Excel that is of a repetitive nature is a good candidate for a macro. For instance, you might have the job of creating financial analysis reports for your company and you want to create a macro that will enter the company name in the current cell and format it using the proper font. Such a task is easily done with a macro.

When you create a macro, you have the opportunity to store it in any of three places. Where you store a macro determines when it is available and how it can be later used. The following are the storage options available in Excel:

  • Personal Macro Workbook. The macro is stored in a special workbook that contains only macros. This workbook is open all the time but is hidden. The filename for this workbook is Personal.xlsb.
  • This Workbook. The macro is stored as a part of the current workbook. (This is the default storage location used by Excel.)
  • New Workbook. A new workbook is created, and the macro is stored within it.

Remember that macros are only available if the workbook in which they are stored is open. Thus, only those stored in your Personal Macro Workbook will be available at all times. This works because the Personal Macro Workbook is always open (even if it is not visible). Macros you store in other workbooks are only available if that workbook is open.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8148) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Understanding Macros.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing Text Case

Word provides a built-in shortcut to change the case of a text selection. Understanding how that shortcut works (and the ...

Discover More

Roman Numerals for Page Numbers

Yes, Excel can work with Roman numerals, and it even provides a worksheet function that converts to them. How you use ...

Discover More

Consolidating Changes under a Single User

When using Track Changes, you may want to have your edits appear to be those of a different user. Here's how to fool Word ...

Discover More

Program Successfully in Excel! This guide will provide you with all the information you need to automate any task in Excel and save time and effort. Learn how to extend Excel's functionality with VBA to create solutions not possible with the standard features. Includes latest information for Excel 2024 and Microsoft 365. Check out Mastering Excel VBA Programming today!

More ExcelTips (ribbon)

Getting a File Name

Does your macro need to allow the user to specify a particular file name that should be used by the macro? Here's a quick ...

Discover More

Checking if a Workbook is Already Open

Knowing if a workbook is already open can be a prerequisite to your macro working correctly. Here's how to check it out.

Discover More

Counting the Times a Worksheet is Used

Do you need to know how many times a worksheet has been used? Excel doesn't track that information, but you can develop ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 9 + 1?

2025-10-20 04:30:05

Mike J

@J.Woolley
Perhaps I should have added:

... unless the function is always preceded by "personal.xlsb!", which seems very tedious, or each of your workbooks have a reference to personal.xlsb. Mine do not since I already had 100s of workbooks before I even started using VBA - hence the add-in comment.

I suppose one could ensure all new workbooks have that reference, but I don't know how that would work when sharing them with other users.


2025-10-19 14:42:07

J. Woolley

A macro is sometimes defined as any VBA code, which typically begins with Sub or Function. I prefer a more specific definition that is consistent with the Macros dialog opened by Developer > Macros (Alt+F8):
    A macro is a Sub with no parameters (a.k.a. arguments).
Therefore, a user-defined function (UDF) is not a macro because it begins with Function, not Sub. And the Macros dialog will not include this procedure

Sub MacroNot(Optional arg As Variant)
    MsgBox "arg is " & IIf(IsMissing(arg), "missing", arg)
End Sub

but it will include this macro

Sub MyMacro()
    MacroNot
    MacroNot "Hello World"
End Sub


2025-10-18 10:38:05

J. Woolley

@Mike J
Yes, the Tip should have discussed an add-in (.xlam), which is similar to Personal.xlsb but must be installed.
See https://excelribbon.tips.net/T008527_Understanding_Add-Ins.html
However, a user-defined function (UDF) in Personal.xlsb should work whenever Personal.xlsb is loaded. Please provide an example of one that doesn't.


2025-10-18 09:31:48

Mike J

personal.xlsb seems to only work globally with SUBs.

If you want to create a UDF that works everywhere, it is better to put it into an Addin.

So that's a 4th important location.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.