If Excel VBA is not working, first check that you are using the desktop version of Excel, the file is saved in a macro-enabled format, and Excel has allowed the macro to run. Then test a simple macro and use any error message or missing result to narrow down whether the problem is security, code placement, an event setting, or incompatible code.
Why Excel VBA may not run
“VBA is not working” can describe several different situations: a macro does not appear in the macro list, clicking a button does nothing, Excel displays a security warning, the code stops with an error, or the macro finishes without changing the expected cells. These symptoms point to different causes, so note exactly what happens before changing settings.
VBA is the programming language used by Excel macros. In Microsoft 365 for Windows, VBA runs in the desktop application; it does not run in Excel for the web. A macro also depends on its workbook, its security permissions, and sometimes other software or system features. A macro written for another computer may therefore behave differently on yours.
Start with the simplest checks: open the workbook in desktop Excel, confirm its file extension, and look for a security notification near the top of the window. If Excel shows an error, record its full text and the line highlighted in the Visual Basic Editor. Those details are more useful than repeatedly clicking the macro button.
Check the workbook format and Excel platform
A workbook saved as an ordinary .xlsx file cannot store VBA code. If you save a macro-containing workbook as .xlsx, Excel warns that the VBA project will be removed; accepting that change can leave you with a workbook that has no macro to run. Use a format designed to retain code, such as .xlsm, or .xlsb. Macro-enabled templates use .xltm.
To check or change the format in Windows Excel, choose File > Save As and select the appropriate file type. Keep an untouched copy before converting or replacing a file, especially if the workbook contains important data or existing macros. If the macro is not listed, check that you opened the intended workbook and that it still contains its VBA project.
Excel for the web can open and edit many macro-enabled workbooks, but it cannot create, edit, or run VBA macros. Open the file in the desktop Excel application to use its macros. Excel for Mac includes VBA, but code that relies on Windows-only technologies, such as certain ActiveX controls or Windows API calls, may not work there. A workbook being visible in a browser or on a Mac does not mean every Windows macro is portable.
Enable macros without weakening security
Excel may block a macro because macros can run harmful code. If the file is trusted and you expected it to contain VBA, review the security warning and the source of the workbook before allowing anything to run. Do not enable macros in an unexpected attachment or a file from an untrusted website just to see whether it works.
In Windows desktop Excel, macro options are under File > Options > Trust Center > Trust Center Settings > Macro Settings. The exact choices can vary with an organization’s policies and Excel version. A notification-based setting lets you decide whether to allow a particular trusted file; enabling all macros globally is not a good troubleshooting shortcut. Work or school administrators may control these settings, in which case contact IT rather than trying to bypass them.
Files downloaded from the internet may be blocked by Windows even when Excel displays no ordinary enable-content prompt. For a file you have independently verified as safe, close Excel, right-click the file in File Explorer, choose Properties, and check whether an Unblock option appears on the General tab. Only unblock a file when you trust its source. Another option for regularly used, trusted files is a carefully controlled Trusted Location, configured in Trust Center settings; do not designate a broad folder such as Downloads as trusted.
Run a small test macro
A small test distinguishes a general VBA or security problem from a problem in a particular macro. In desktop Excel for Windows, open the Visual Basic Editor with Alt+F11, choose Insert > Module, and paste the code below into the new standard module. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon by checking Developer. On a Mac, the Visual Basic Editor shortcut may require Option+F11 or the Fn key, depending on the keyboard; the Developer tab or Tools menu is another route.
Option Explicit
Public Sub TestMacro()
' Display a message to confirm that this procedure ran.
Dim message As String
message = "VBA is running."
MsgBox message, vbInformation, "VBA check"
End Sub
Before running any macro, save a copy of the workbook: macros cannot be undone with Ctrl+Z. In the Visual Basic Editor, place the cursor inside TestMacro and press F5, or return to Excel and use Developer > Macros to select TestMacro and choose Run. On a Mac, shortcut behavior can differ, so use the Run command in the editor if needed. If the message appears, VBA can run and the original problem is more likely specific to the workbook’s procedure, trigger, or code.
If the test macro is blocked, missing, or produces an error, check security, platform, and file format before troubleshooting the original procedure. If it works from the editor but not from a worksheet button, the issue is probably the button assignment or how the procedure is called.
Check where the code is stored and how it starts
Not all VBA procedures run the same way. A regular macro intended to be run manually usually belongs in a standard module, created with Insert > Module in the Visual Basic Editor. If it is stored in a worksheet’s code module or ThisWorkbook, it may not appear in the regular Macros list. Conversely, event procedures belong in the relevant worksheet or workbook module.
For example, a Worksheet_Change procedure is an event handler, not a macro that you normally start from the Macros dialog. It must be in the code module for the worksheet it is meant to monitor, and it runs when a cell on that sheet changes. It will not necessarily respond to every kind of change: changes made by another macro do not trigger events by default. A procedure intended to run when the workbook opens must be placed in ThisWorkbook as the appropriate workbook event procedure.
Buttons have their own common failure modes. A Form Control button can be assigned to a macro using Assign Macro, but that assignment may point to a procedure in a different workbook or to an old macro name. ActiveX controls have separate design-mode and event-code behavior and are not supported in the same way on Mac. Confirm which kind of control you are using, whether design mode is active, and whether the assigned procedure still exists.
Use error messages to find code problems
If Excel reports a compile or runtime error, do not treat it as a security warning. A compile error means VBA cannot interpret or compile some code, often because of a missing statement, misspelled name, or incompatible declaration. A runtime error occurs after execution starts, for example when code refers to a worksheet that is not present or tries to use an unavailable object. Choose Debug when offered to see the line where execution stopped, then inspect that line and the values it depends on.
In the Visual Basic Editor, Debug > Compile VBAProject can reveal compile problems before you run a procedure. The menu item may be unavailable if the project is already compiled. Fix the first reported problem and compile again, since one syntax error can cause misleading errors later in the code. If a procedure appears to pause, it may be in break mode: use Run > Reset in the editor, then start it again after correcting the cause.
Code copied from a Windows computer can also rely on a missing reference. In the editor, open Tools > References and look for an item marked MISSING. A project may need a library installed on the computer or a reference adjusted; do not select a replacement at random, because the code may expect specific objects or methods. If the code uses Windows API declarations, 64-bit Office may require declarations marked PtrSafe and appropriately sized pointer variables. Changing declarations without understanding their purpose can introduce errors, so ask the macro’s author for a compatible version when possible.
Check events, buttons, and Excel’s current state
Some macros depend on Excel settings that can be left in an unexpected state after an earlier procedure stops. For instance, code may turn off application events to avoid triggering other event procedures, then fail before turning them back on. In that case, ordinary worksheet event macros can appear broken even though manually run procedures still work.
In the Visual Basic Editor, open the Immediate window with Ctrl+G on Windows. You can enter Application.EnableEvents = True and press Enter to restore events for the current Excel session. This does not fix the underlying macro that disabled them, so inspect the code for a reliable cleanup step. Similarly, a macro that changes calculation to manual may leave formulas looking out of date; check Formulas > Calculation Options if results are not recalculating. These settings affect symptoms, but they do not explain every macro failure.
If a macro runs but has no visible effect, check its assumptions: the active workbook, selected worksheet, expected column headings, and input range may differ from what the code expects. A macro that uses ActiveSheet can act on the wrong sheet if another tab is selected. A blank or filtered range can also produce a result that looks like nothing happened. Inspect the procedure’s target cells and any status or error messages before assuming VBA did not start.
Reduce repeat problems and choose a safe fix
For a workbook you did not create, ask its author what Excel version, operating system, file format, and supporting add-ins or references it requires. This can quickly distinguish a broken workbook from an incompatible environment. Keep an original copy, and test repairs on a duplicate rather than on the only copy of important business data.
- Keep macro workbooks in .xlsm, .xlsb, or another format that supports VBA, and confirm the correct file is open.
- Allow code only when you trust its source; use a notification prompt or a narrowly scoped trusted location rather than turning off protections broadly.
- Check whether the procedure is a standard macro, a worksheet event, a workbook event, or a control’s assigned procedure.
- Record the exact error text and highlighted line, then fix compile errors before investigating later behavior.
- For Windows-only code, ask for a Mac-compatible alternative or run the workbook in desktop Excel for Windows where appropriate.
When troubleshooting a macro you wrote, add clear error handling and ensure settings such as EnableEvents or ScreenUpdating are restored even if execution fails. Avoid adding broad error suppression simply to make an error disappear: it can conceal the actual fault and leave the workbook in a confusing state. If the file is from a business system, a vendor, or an unknown source, the safest fix may be to obtain a supported version from its owner rather than editing its security or code yourself.
Frequently Asked Questions
Why is my macro not showing in the Macro dialog?
Check that the code is in a standard module, the procedure is a public Sub without required arguments, and you are looking in the correct open workbook. Private procedures and worksheet or workbook event handlers generally do not appear as ordinary runnable macros.
Why does Excel say macros have been blocked?
Excel or Windows may block code because of security settings, an internet download, or an organization policy. Verify the file’s origin first. If it is trusted, review the notification or ask your administrator about the approved way to run it; do not enable every macro globally.
Can I run a VBA macro in Excel for the web?
No. Excel for the web does not run VBA. Open the workbook in the desktop Excel application to run its macro. The workbook can still be stored or shared online, but the VBA procedure must run in desktop Excel.
Why does a worksheet-change macro not run?
Confirm that the event procedure is in the code module for the worksheet being edited and that application events are enabled. Also check that the change is made directly on the sheet: another macro changing cells will not automatically fire worksheet events unless the code handles that behavior.
Can I undo a macro with Ctrl+Z?
No. Running a VBA macro clears Excel’s normal undo history, so Ctrl+Z cannot reverse its changes. Save a separate copy before running unfamiliar or data-changing code, and test it on sample data first.
Related
- How to Open Solver in Excel and Enable the Solver Add-in
- Find Solver Parameters in Excel and Understand Each One
- How to Find a Z-Score Using Excel Solver Step by Step
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Outlook Excel VBA: Automate Email and Calendar TasksYes—Excel VBA can automate classic Outlook for Windows, including creating email drafts from spreadsheet rows and working with…
- VBA Range.Clear: What It Clears, Keeps, and How to Use ItIn Excel VBA, Range.Clear clears the specified cells, removing their values or formulas and their cell formatting, along…
- Excel VBA Message Box: How to Use MsgBox in MacrosIn Excel VBA, use the MsgBox function to show a message, optionally display buttons or an icon, and…
- Excel VBA to List File Names in All Subfolders AutomaticallyTo list file names from a folder and all its subfolders in Excel for Microsoft 365 on Windows,…
- Excel Macro VBA Tutorial: Write and Run a First MacroAn Excel macro is a set of instructions that automates actions in a workbook, and VBA (Visual Basic…
- Excel VBA: Match a Trendline Label to Its Line ColorYes. In Excel VBA, set the trendline label’s font color to the trendline’s line color: use Trendline.DataLabel.Font.Color and…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.