Edit a macro

Applies To
Excel for Microsoft 365 Excel 2024 Excel 2021

To edit a macro that you attached to a Microsoft Excel workbook, use the Visual Basic Editor.

Important

Before you can work with macros, you need to enable the Developer tab. For more information, see Show the Developer tab.

Change macro security settings

To edit and run macros, set the security level to temporarily enable all macros:

  1. On the Developer tab, in the Code group, select Macro Security.

    Screenshot that shows the Code group on the Developer tab.

  2. Under Macro Settings, select Enable VBA macros (not recommended, potentially dangerous code can run), and then select OK.

    Warning

    To help prevent potentially dangerous code, return to any of the settings that disable all macros after you finish working with macros.

Edit the macro

  1. On the Developer tab, in the Code group, select Macros.
  2. In the Macro name box, select the macro that you want to edit.
  3. Select Edit. The Visual Basic Editor opens.

Tip

To get help while working in the Visual Basic Editor, on the Help menu, search for Microsoft Visual Basic Help, or press F1.