How to Create a Macro In Excel
How to Create a Macro In Excel
Automate your recurring tasks with simple macros
by Tricia Goss
Updated on February 05, 2021
- Tweet
- Share
What to Know
- Open the Developer tab and choose Record Macro. Add a name and shortcut for macro. In the drop-down, choose This Workbook > OK.
- Once created, perform formatting commands for the new macro, then choose Stop Recording > File > Save As. Save as an .xlsm file.
- The Developer tab isn't visible by default. To enable, open Options (PC) or Preferences (Mac). Open Ribbon settings, select Developer.
Microsoft Excel's spreadsheet configuration, formatting abilities, and formula functions allow you to perform repetitive tasks. You can streamline those tasks further by using macros. Learn how to do this with Excel for Microsoft 365, Excel 2019, Excel 2016, Excel 2013, Excel 2010, Excel for Microsoft 365 for Mac, Excel 2019 for Mac, and Excel 2016 for Mac.
How to Display the Developer Tab in Excel for Microsoft 365, Excel 2019, Excel 2016, Excel 2013, and Excel 2010
Before you add macros in Excel, display the Developer tab on the ribbon. By default, the Developer tab is not visible.
Go to the File tab and then select Options.
In the Excel Options dialog box, select Customize Ribbon.
In the Customize the Ribbon list, go to the Main Tabs section and select the Developer check box.
Select OK to add the Developer tab to the ribbon.
How to Create a Macro in Excel for Microsoft 365, Excel 2019, Excel 2016, Excel 2013, and Excel 2010
When you're ready to create a macro, start Excel and open a worksheet.
Macros cannot be created or run in Excel Online. However, Excel Online opens workbooks containing macros. You can make changes to worksheets and save workbooks in Excel Online without affecting macros.
Go to the Developer tab.
In the Code group, select Record Macro.
In the Macro Name text box, enter a descriptive name for the macro.
Enter a shortcut key for the macro.
Select the Store Macro In drop-down arrow and choose This Workbook.
Select OK.
Perform the formatting and commands you want to include in the macro.
Select Stop Recording when you're finished.
Go to the File tab and then select Save As or press F12.
In the Save As dialog box, enter a file name for the workbook.
Select the Save as Type drop-down arrow, choose Excel Macro-Enabled Workbook and then select Save.
How to Display the Developer Tab in Excel for Microsoft 365 for Mac, Excel 2019 for Mac, and Excel 2016 for Mac
Before you add macros in Excel for Microsoft 365 for Mac or in Excel 2019 or 2016 on a Mac, display the Developer tab on the ribbon. By default, the Developer tab is not visible.
Go to Excel and choose Preferences.
Select Ribbon & Toolbar.
In the Customize the Ribbon section, go to the Main Tabs list and select the Developer check box.
Select Save.
How to Create a Macro in Excel for Microsoft 365 for Mac, Excel 2019 for Mac, and Excel 2016 for Mac
When you're ready to create a macro, start Excel and open a worksheet.
Go to the Developer tab.
In the Code group, select Record Macro.
In the Macro Name text box, enter a name for the macro.
In the Shortcut key text box, type the lowercase or uppercase letter you want to use.
Select the Store macro in drop-down arrow and choose This Workbook.
Select OK.
Perform the formatting and commands you want to include in the macro.
When you're finished, go to the Developer tab and select Stop Recording.
Go to the File tab and select Save As or, press Shift+Command+S.
In the Save As dialog box, enter a file name for the workbook.
Select the File Format drop-down arrow, choose Excel Macro-Enabled Workbook (.xlsm). Then select Save.
How to Run a Macro
When you want to run a macro you created in Excel, either use the shortcut you assigned to the macro or run the macro from the Developer tab.
To run a macro using a combination shortcut key, open the worksheet containing the macro. Enter or select the data on which you want to apply the formatting or commands included in the macro. Then, press the key combination assigned to the macro.
To run a macro from the Developer Tab, open the worksheet containing the macro, then follow these steps:
In Excel, enter any data on which you want to apply the formatting or commands you included in the macro.
Go to the Developer tab.
In the Code group, select Macros.
In the Macro dialog box, choose the name assigned to the macro, then select Run.
How to Change the Macro Shortcut Key
To add or change a combination shortcut key for a macro:
Go to the Developer tab.
In the Code group, select Macros.
In the Macros dialog box, select the name of the macro for which you want to assign or change the combination shortcut key.
Select Options.
In the Macro Options dialog box, go to the Shortcut key text box, type the lowercase or uppercase letter to use for the combination shortcut, and then select OK.
Was this page helpful?
More from Lifewire
How to Create an Excel Lookup Formula With Multiple Criteria
Hide/Unhide Scroll Bars and Reset the Vertical Slider Range in Excel
Get the Latest Tech News Delivered Every Day
Email Addressenter
Follow Us
- About Us
- Advertise
- Privacy Policy
- Cookie Policy
- Careers
- Editorial Guidelines
- Contact
- Terms of Use
- California Privacy Notice
Lifewire is part of the Dotdash publishing family.