LearnExcel.io
Menu

How to Create Macros in Excel

Written by ··Updated June 16, 2026

To create a macro in Excel, enable the Developer tab (File > Options > Customize Ribbon), then click Developer > Record Macro, perform your actions, and click Stop Recording. Save the file as a macro-enabled workbook (.xlsm) so your macros are preserved, and use Alt+F11 to open the VBA editor if you want to view or edit the code.

Microsoft Excel is a powerful tool that helps individuals and organizations manage data. One of the great features of Excel is the ability to automate repetitive tasks using Macros. Macros are a series of commands and actions that can be recorded and played back to save time and increase productivity. Whether you are a beginner or an advanced Excel user, learning how to create Macros can greatly enhance your workflow. This blog post provides a concise guide on how to create Macros in Excel, so that you can automate the tasks that you perform frequently and improve your overall efficiency.

What are Macros in Excel?

Before diving into how to create Macros in Excel, it’s important to understand what they actually are. In short, Macros are a set of instructions that automate repetitive tasks in Excel. This means that you can record a sequence of actions and then apply that sequence to similar data sets, saving you valuable time and energy.

Enabling the Developer Tab

Before you can start creating Macros in Excel, you need to ensure that the Developer Tab is enabled. This tab normally isn’t visible, so you’ll need to make it visible by going to File > Options > Customize Ribbon > and checking the box next to Developer. For a more detailed walkthrough, see our guides on how to enable the Developer tab in Excel and how to add the Developer tab to Excel.

Recording a Macro

Now that you have the Developer Tab enabled, it’s time to record your first Macro. To do this, follow these steps:

  1. Click the Developer Tab, select Record Macro.
  2. Give your Macro a name and description.
  3. Choose where you want to store the Macro (whether in a Personal Macro Workbook or in the current workbook).
  4. Begin performing the actions that you want to automate.
  5. Once you’ve completed the actions, select Stop Recording from the Developer Tab.

For more on this process, see our dedicated guide on how to record a macro in Excel. If you’d rather write code than record actions, you can open the Visual Basic editor with the Alt+F11 shortcut (Option+F11 or Fn+Option+F11 on a Mac) — learn more in our guide to opening the VBA editor in Excel.

Assigning a Keyboard Shortcut to Your Macro

Now that you’ve recorded your Macro, it’s time to assign it a keyboard shortcut. This allows you to perform the Macro with a simple keyboard combination, saving you even more time. To assign a keyboard shortcut, follow these steps:

  1. Go to the Developer Tab and select Macros.
  2. Select the Macro that you want to assign the shortcut to and select Options.
  3. Choose a keyboard shortcut by typing a letter, number, or function key that you want to use.
  4. Hit OK, and your Macro is now ready to use with the keyboard shortcut you chose.

Running Your Macro

Now that you’ve recorded your Macro and assigned it a keyboard shortcut (if desired), it’s time to run it. To do this, simply press the keyboard shortcut or go to the Developer Tab and select Macros. Choose the Macro, and it will run automatically, applying the actions that you recorded. See our full guide on how to run a macro in Excel for more options.

Saving a Workbook That Contains Macros

Macros cannot be saved in a standard .xlsx workbook. When you try to save a file that contains macros, Excel will prompt you to keep your code by saving it in a macro-enabled format. Go to File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) as the file type. If you save over the .xlsx format, your macros will be stripped out. When you reopen an .xlsm file, Excel may show a security warning — click Enable Content (or use the Trust Center) to allow the macros to run.

Creating and utilizing Macros in Excel can greatly improve your workflow and productivity. With just a few simple steps, you can automate repetitive tasks, saving you valuable time and energy. By following the steps outlined in this guide, you can easily create Macros in Excel and start using them today.

Best Practices for Creating Macros

While Macros can be incredibly helpful in streamlining your workflow, it’s important to keep a few things in mind to ensure that you are creating effective Macros. Here are a few best practices to follow:

  • Only automate tasks that you perform frequently and that have a clear and consistent process.
  • Make sure that your Macro is flexible enough to work with different datasets.
  • Test your Macro with different datasets to ensure that it works as intended.
  • Document your Macro with clear descriptions so that you or others can easily understand what it does.
  • Consider adding error handling to your Macro to prevent crashes or other issues.

Resources for Learning More About Macros

If you’re interested in learning more about Macros and how to use them in Excel, there are a number of great resources available to help you. Here are a few that we recommend:

Creating Macros in Excel is a powerful way to automate repetitive tasks and save time in your daily work. By following the steps outlined in this post and keeping best practices in mind, you can easily create your own Macros and optimize your workflow.

Frequently Asked Questions

Here are some frequently asked questions about creating Macros in Excel:

Can Macros be edited or modified after they have been created?

Yes, you can edit or modify Macros after they have been created. To do this, go to the Developer Tab and select Macros. Choose the Macro that you want to edit and select Edit. This opens the macro in the Visual Basic editor, where you can change the code and save it. See our guide on how to edit macros in Excel for details.

Can Macros be shared between different Excel workbooks?

Yes, Macros can be shared between different Excel workbooks. You can do this by saving the Macro in your Personal Macro Workbook, which can be accessed from any Excel workbook.

Is programming knowledge necessary to create Macros?

No, programming knowledge is not necessary to create Macros in Excel. You can use the Macro recording feature to record your actions and create the Macro automatically.

Can Macros be created in other spreadsheet programs besides Excel?

While other spreadsheet programs may have similar features, Macros are specific to Excel and cannot be created in other spreadsheet programs.

How can I backup my Macros?

To backup your Macros, you can export them to a separate file or copy them to a backup location. To export a Macro, go to the Developer Tab and select Macros. Choose the Macro that you want to export and select Export. Choose a location and save the file. Alternatively, you can copy the contents of your Personal Macro Workbook to a backup location on your computer.

What file format do I need to save a workbook with macros?

You must save the file as an Excel Macro-Enabled Workbook with the .xlsm extension. The default .xlsx format cannot store macros, so Excel will warn you and discard the code if you keep that format. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) from the file type list.

How do I enable macros so they will run?

When you open an .xlsm file, Excel typically displays a security banner because macros are disabled by default for safety. Click Enable Content in that banner to allow the macros to run. You can also manage these settings under File > Options > Trust Center > Trust Center Settings > Macro Settings. See our guide on how to enable macros in Excel for more.

Can I record macros in Excel for Mac?

Yes. Excel for Mac includes the Developer tab and the Record Macro feature, which you enable via Excel > Preferences > Ribbon & Toolbar. Note that macro recording on Mac has historically been more limited than on Windows — some actions may not record reliably, and the VBA editor opens with Option+F11 (or Fn+Option+F11) rather than Alt+F11. For complex automation, you may need to write or adjust the VBA code by hand.

What is the keyboard shortcut to open the VBA editor?

Press Alt+F11 on Windows to open the Visual Basic for Applications (VBA) editor, where you can view and edit your macro code. On a Mac, use Option+F11 (or Fn+Option+F11 on keyboards where F-keys default to media controls). Learn more in our guide to opening the VBA editor in Excel.

Related guides

Excel Macros and VBA

What Is a Macro Excel

Learn what a macro Excel is and how it can help automate tedious tasks in your spreadsheets. Get tips on creating and using macros for efficient Excel work.

May 20, 2023

View all Excel Macros and VBA guides →