Delete a macro by removing it from the Visual Basic Editor

To delete a macro in Excel, open the Visual Basic Editor, find the macro's code in the Project Explorer panel on the left, right-click the module that contains it, and select Delete [Module Name]. This removes the entire module and all macros stored in it. If you want to keep the module but delete only one macro, you can select and delete just the code for that specific macro instead.

The Visual Basic Editor is where Excel stores all macro code. When you delete a module, Excel removes it permanently — there's no undo after you close the editor, so make sure you're deleting the right one. If you're unsure which module contains the macro you want to remove, you can open each module to read the code inside before deleting.

Key Takeaways

  • Open the Visual Basic Editor by pressing Alt+F11 (Windows) or Fn+Option+F11 (Mac), or go to Developer tab > Visual Basic.
  • Right-click a module in the Project Explorer and select Delete to remove all macros in that module at once.
  • To delete only one macro, open the module, select the entire macro code (from Sub to End Sub), and press Delete.
  • Deleting a macro in the editor is permanent and cannot be undone after you close the file, so verify you're removing the correct code first.
  • If the Developer tab is not visible, enable it in Excel Options (Windows) or Preferences (Mac) under the Ribbon & Toolbar section.

Open the Visual Basic Editor

The fastest way to reach the Visual Basic Editor is to press Alt+F11 on Windows or Fn+Option+F11 on Mac. The editor opens in a new window showing your macro code.

If the keyboard shortcut doesn't work, you can also open it through the ribbon. On Windows, click the Developer tab and select Visual Basic. On Mac, go to Tools > Macro > Visual Basic Editor. If you don't see the Developer tab on Windows, right-click the ribbon, select Customize the Ribbon, check the Developer box, and click OK.

Find the macro you want to delete

When the Visual Basic Editor opens, look at the left side for the Project Explorer panel. It shows a tree of your workbook's contents, including folders labeled Microsoft Excel Objects and Modules. Macros are stored in the Modules folder or sometimes in Sheet objects if they were recorded directly on a sheet.

Click the plus sign next to Modules to expand it and see the list of modules. Each module may contain one or more macros. If you're not sure which module holds the macro you want to delete, click on each one to see the code in the main editor window. The macro name appears after the word Sub at the start of each macro's code.

Delete the entire module or just the macro code

If you want to remove all macros in a module, right-click the module name in the Project Explorer and select Delete [Module Name]. A dialog box asks you to confirm. Click Yes to delete the module and all macros it contains.

If you want to keep the module but delete only one macro, open the module by clicking on it, then select all the code for that macro. A macro's code starts with a line like Sub MacroName() and ends with End Sub. Highlight from the first line to the last line of that macro, including both the Sub and End Sub lines, then press Delete. The rest of the module stays intact.

Save your workbook after deleting

After you delete a macro or module, close the Visual Basic Editor by clicking the X button or pressing Alt+Q. You return to your spreadsheet. Save the file by pressing Ctrl+S (Windows) or Cmd+S (Mac) to save the changes.

Deletion is permanent once you save. If you realize you deleted the wrong macro, you can undo by pressing Ctrl+Z or Cmd+Z immediately — but only before you save. After you save and close the file, the macro is gone and cannot be recovered from within Excel. If you need the macro back, you would have to restore it from a backup copy of the file.

Disable a macro without deleting it

If you're not ready to delete a macro permanently but want to stop it from running, you can disable it instead. When you open a file with macros, Excel shows a security warning bar asking whether to enable or disable macros. Click Don't Enable to prevent all macros in that file from running without deleting them.

You can also disable macros at the application level. On Windows, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Disable all macros without notification. On Mac, go to Excel > Preferences > Security & Privacy > Macro Security and choose a restriction level. This approach keeps your macros in the file but prevents them from running until you change the setting back.

Frequently Asked Questions

Can I undo a macro deletion after I save the file?

No. Once you save the file after deleting a macro, it cannot be recovered within Excel. You can undo immediately after deletion if you haven't saved yet by pressing Ctrl+Z or Cmd+Z. If you've already saved, your only option is to restore the file from a backup copy.

What's the difference between deleting a module and deleting a macro?

Deleting a module removes the entire container and all macros stored in it. Deleting a macro removes only the code for that one macro while keeping the module and any other macros in it. Choose based on whether you want to remove everything in the module or just one macro.

Why can't I see the Developer tab?

The Developer tab is hidden by default. On Windows, right-click the ribbon, select Customize the Ribbon, check the Developer box, and click OK. On Mac, go to Excel > Preferences > Ribbon & Toolbar and check Developer in the list.

Will deleting a macro affect my spreadsheet data?

No. Deleting a macro removes only the code that performs actions — it does not change any data in your cells or sheets. Your spreadsheet contents stay exactly as they are.

How do I know which macro is safe to delete?

Open each module in the Visual Basic Editor and read the macro names and code. Look for comments (lines starting with a single quote) that explain what the macro does. If you created the macro or have documentation about it, that's your best guide. When in doubt, disable the macro first to see if anything stops working before you delete it.