If your Excel code isn’t running, start by checking macro security settings and ensuring the code is in the correct location—this often resolves the issue immediately.

What You'll Need

  • Microsoft Excel (2016 or later recommended)
  • A workbook containing the VBA code or formulas that aren’t working
  • Access to the Developer tab (may need to be enabled)
  • Basic familiarity with the VBA editor or formula bar

Step-by-Step

  1. Enable the Developer tab: Go to File > Options > Customize Ribbon. Under Main Tabs, check the box for Developer, then click OK. (Note: Labels may vary slightly by Excel version or region.)
  2. Check macro security settings: With the Developer tab visible, click Macro Security. Select "Enable all macros" (not recommended for long-term use; see Tips) or "Disable all macros with notification" to get prompted when opening the file. Click OK.
  3. Ensure the workbook is saved as a macro-enabled file: Click File > Save As. Choose "Excel Macro-Enabled Workbook (*.xlsm)" from the file type dropdown. If you saved it as .xlsx, macros will not run—resave it correctly.
  4. Verify the code is in the right place: Press ALT+F11 to open the VBA Editor. In the Project Explorer, confirm your code is in a standard module (Insert > Module), not in a sheet or ThisWorkbook module unless intended for those events.
  5. Check for syntax errors: In the VBA Editor, click Debug > Compile VBAProject. If errors appear, fix them (e.g., missing End Sub, misspelled variables) before running again.
  6. Run the macro: Close the VBA Editor. On the Developer tab, click Macros, select your macro, and click Run. Alternatively, press ALT+F8, choose the macro, and hit Run.
  7. Test a simple macro to isolate the issue: Insert a new module and paste: Sub TestMacro() MsgBox "Hello, Excel!" End Sub Run this. If it works, the issue is in your original code, not Excel’s macro system.
  8. For formulas not calculating: Go to Formulas > Calculation Options and ensure it’s set to Automatic. If set to Manual, press F9 to force calculation.
  9. Check for disabled add-ins: File > Options > Add-ins. At the bottom, manage Excel Add-ins and ensure relevant ones (like Analysis ToolPak) are checked.
  10. Look for protected view or external links: If the file came from email or the internet, Excel may open it in Protected View. Click Enable Editing if prompted, as macros won’t run in Protected View.

Common Mistakes

  • Saving a macro-containing workbook as .xlsx instead of .xlsm, which strips all VBA code.
  • Assuming macros are enabled by default—many organizations disable them via Group Policy for security.
  • Placing event code (like Worksheet_Change) in a standard module instead of the sheet’s code window.
  • Using outdated Excel versions where macro functionality is limited or blocked.
  • Ignoring the yellow security warning bar that appears when opening a file with macros.
  • Having circular references in formulas that prevent calculation, mistaken for code failure.

Tips

  • Use "Disable all macros with notification" as a secure default—you’ll get a prompt to enable content when opening trusted files.
  • Digitally sign your macros with a self-signed certificate (via SelfCert.exe) to avoid repeated security prompts.
  • Comment your code thoroughly; it makes debugging syntax errors much faster.
  • Break long macros into smaller subs to isolate where execution stops.
  • Use Debug.Print statements and the Immediate Window (CTRL+G in VBA Editor) to trace variable values.
  • If macros are blocked by Group Policy, contact your IT department—they may need to adjust policy or approve your certificate.
  • Regularly update Excel; older versions may have unpatched macro-related bugs.

Troubleshooting

  • Macros still won’t run after enabling them: Check if your antivirus software is blocking Excel’s macro execution. Temporarily disable it (safely) to test, then re-enable and add an exception if needed.
  • Get a "Cannot run the macro" error: The macro may be corrupted. Try importing it into a new module or recreating it from a backup.
  • Excel freezes or crashes when running code: You likely have an infinite loop. Press ESC or CTRL+BREAK to stop it, then review your Do While or For loops for missing exit conditions.
  • Formulas show as text instead of calculating: The cell may be formatted as Text. Select the cell, change format to General or Number, then press F2 and Enter to re-enter the formula.
  • Workbook runs slowly with macros: Turn off screen updating during execution with Application.ScreenUpdating = False, and remember to set it back to True at the end.
  • None of the above works: Repair Excel via Control Panel > Programs > Microsoft Office > Change > Quick Repair. If unresolved, try an Online Repair.
  • Frequently Asked Questions

    Why do my macros work on my computer but not on others?

    Macro security settings, Group Policy, or missing references (Tools > References in VBA Editor) may differ on other machines. Ensure referenced libraries are available.

    Can I run Excel macros in Excel Online or mobile apps?

    No. Excel Online and mobile apps do not support VBA macros. Use desktop Excel for full macro functionality.

    Is it safe to enable all macros?

    Only if you trust the source. Enabling all macros exposes you to malware. Use notification mode and verify the publisher instead.

    How do I find where a macro is stored?

    Press ALT+F11, then in the Project Explorer, look under Modules, Sheets, or ThisWorkbook. Macros can be in any of these locations.

    What does "compilation error" mean in the VBA Editor?

    It means the code has a syntax issue—like a missing keyword, typo, or incorrect structure—that prevents Excel from understanding it before running.

    Can macros modify or delete my data permanently?

    Yes. Always test macros on a copy of your data first. Consider adding undo logic or confirmation prompts for destructive actions.