If an Excel VBA worksheet change event is not working, first check that the Worksheet_Change procedure is in the correct worksheet’s code module, macros are enabled, and Application.EnableEvents is set to True. Also confirm that the edit is a direct cell change: recalculating a formula does not trigger this event.
What the Worksheet_Change event does
Worksheet_Change is an event procedure that runs when cells on a particular worksheet are changed. It can respond to a person typing a value, pasting cells, clearing contents, or to certain changes made by another workbook or VBA code. Excel supplies a Target argument: a Range representing the cell or cells that changed.
The event is tied to one worksheet, rather than being a general macro that runs everywhere. Its usual uses include adding a timestamp when an input is edited, checking entries, updating a related cell, or reacting to a pasted value. The code runs in Excel for Windows desktop when the workbook’s macros are allowed to run.
A key distinction is that a cell’s displayed result can change without the cell itself being edited. If A1 contains a formula and its result changes because another cell was edited, that recalculation does not fire Worksheet_Change for A1. For formula-result changes, consider the worksheet’s Worksheet_Calculate event instead, while accounting for the fact that it runs on recalculation and does not provide a changed-cell Target.
Put the procedure in the worksheet module
The most common cause is putting the code in the wrong place. A worksheet event belongs in that worksheet’s object module, not in a standard module such as Module1 and not in the ThisWorkbook module. A standard macro in a regular module can be run directly, but Excel will not treat it as a worksheet event procedure there.
- Open the workbook in Excel desktop and press Alt+F11 on Windows to open the Visual Basic Editor.
- In Project Explorer, find the workbook and expand its Microsoft Excel Objects folder. If Project Explorer is hidden, use View > Project Explorer in the Visual Basic Editor.
- Double-click the worksheet object where the edit happens, such as
Sheet1 (Orders), and put the event code in that code window. - Choose
Worksheetfrom the left dropdown andChangefrom the right dropdown to have the editor insert the event procedure framework.
The name in parentheses usually reflects the visible sheet tab name; the object name before it is the sheet’s VBA code name. Using Me inside the event procedure refers to the worksheet that owns the code, which helps avoid accidentally targeting a different sheet.
Check macros and the workbook format
VBA will not run if macros are blocked. Make sure the file is saved in a macro-capable format such as Excel Macro-Enabled Workbook (.xlsm) or Excel Binary Workbook (.xlsb). Saving a workbook containing VBA as .xlsx removes its VBA project. Close and reopen the macro-capable file, then allow macros only if you trust its source.
Excel for the web can open a workbook containing VBA, but it cannot run or edit VBA macros. Test the event in the Excel desktop application. On Mac, Excel supports VBA, although some Windows-specific features and controls are unavailable; keyboard shortcuts may also require the Fn key depending on the keyboard. The event code itself is often portable, but Windows API calls and ActiveX-dependent code are not reliable cross-platform choices.
Do not solve a blocked-macro problem by enabling every macro globally. If the workbook is from an unknown source, leave it disabled and verify the file before trusting it. Macro security affects whether VBA runs at all; it is separate from whether an event procedure is correctly written.
Verify EnableEvents is on
Application.EnableEvents is an application-wide setting. If it is False, Excel suppresses events, including worksheet change events. This can happen when a macro turns events off to prevent a loop and then stops because of an error before turning them back on. The setting can affect other open workbooks in the same Excel session too.
In the Visual Basic Editor, open the Immediate window with Ctrl+G on Windows. Enter ?Application.EnableEvents and press Enter to inspect the current value. If it returns False, enter Application.EnableEvents = True and press Enter. On Mac, use the Visual Basic Editor’s View menu to find the Immediate window if the Windows shortcut does not apply.
Turning events back on can restore event handling, but it does not repair the macro that left them off. Review any code that assigns False to EnableEvents and make sure it restores the setting even if a later line fails.
Confirm that the changed cells match the code
A procedure can run correctly and still appear broken if it exits before doing anything. For example, code may intentionally watch only A2:A100. Editing a cell outside that range should produce no visible action. The event’s Target can also represent many cells at once when a user pastes or clears a block, so code that assumes a single cell may process only the first row or fail.
This example watches A2:A100 and writes a date and time in column B for every changed cell in that range. Put it in the relevant worksheet’s code module. It handles multi-cell pastes and restores events if an error occurs.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim changedCells As Range
Dim cell As Range
On Error GoTo ErrHandler
Set changedCells = Intersect(Target, Me.Range("A2:A100"))
If changedCells Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each cell In changedCells.Cells
Me.Cells(cell.Row, 2).Value = Now
Me.Cells(cell.Row, 2).NumberFormat = "yyyy-mm-dd hh:mm:ss"
Next cell
SafeExit:
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox "Worksheet_Change failed: " & Err.Description, vbExclamation
Resume SafeExit
End Sub
The intersection check prevents edits elsewhere on the sheet from triggering the timestamp action. The loop matters because a paste can change multiple watched cells at once. Since writing to column B is itself a cell change, the procedure disables events before writing, preventing its own output from triggering another run. This example stamps the time even when a watched cell is cleared.
Before running or adapting a macro, save a copy of the workbook. VBA changes cannot be undone with Ctrl+Z, so test on a copy if the code could overwrite data.
Look for early exits, errors, and event loops
Search the procedure for conditions that stop it, such as Exit Sub, an If statement, or an Intersect check using the wrong range or worksheet. A misspelled sheet reference, a protected output cell, or an unexpected value can also stop the intended action. If the Visual Basic Editor highlights a line or displays an error, read the message and fix the underlying problem rather than repeatedly dismissing it.
Watch for event loops. If the change handler writes to a cell and that write triggers another change handler, the code can run repeatedly. Disabling events only around the write and restoring them on every exit is a common safeguard. Avoid leaving events disabled as a permanent workaround: other event code in open workbooks will stop working too.
Also check whether another macro replaces, clears, or overwrites the cell you expect to inspect. If the code is meant to respond to changes in a different worksheet, a worksheet-level event in the original sheet will not observe them. Use an event in the sheet being edited, or design a workbook-level solution where appropriate.
A practical debugging sequence
Work through the checks in order so you can separate an Excel setup issue from a logic error:
- Confirm you are editing the workbook in desktop Excel, not Excel for the web, and that the file is saved in a macro-capable format.
- Confirm the workbook’s macros are allowed and that the code is in the worksheet object for the sheet being edited.
- Check that the procedure signature is exactly
Private Sub Worksheet_Change(ByVal Target As Range)and that it has not been renamed or placed inside another procedure. - Check
Application.EnableEventsin the Immediate window, then inspect code that may have disabled events. - Temporarily place a breakpoint on the first executable line and edit a cell. If execution stops there, the event fires and the remaining issue is in the procedure’s logic.
- If execution never reaches the breakpoint, recheck the module, macro security, application setting, and whether the action was a formula recalculation rather than a direct edit.
You can set a breakpoint by clicking the margin beside a line in the Visual Basic Editor. When the procedure pauses, step through it with F8 on Windows and inspect Target.Address in the Immediate window. Remove the breakpoint when finished by clicking the margin again. A temporary message box can also help confirm execution, but remove it afterward because it interrupts normal editing.
When to use another event or approach
Choose the event based on what actually changes. Use Worksheet_Change for direct edits to cell contents. Use Worksheet_Calculate when the action depends on formula results changing after recalculation, and compare the relevant values yourself if you need to determine what changed. A calculation event may run more often than expected, so keep its code efficient and avoid writing to cells in a way that causes repeated recalculation.
If the goal is simply to display a result based on other cells, a worksheet formula may be easier to maintain than an event macro. If the task is a repeatable transformation of a table, Power Query may be a better fit than code that reacts to every keystroke. Office Scripts are a separate automation option in supported Microsoft 365 environments, but they are not a drop-in replacement for a VBA worksheet change event.
Frequently Asked Questions
Why does Worksheet_Change not run when a formula result changes?
Because the formula cell is recalculated, not directly edited. Use Worksheet_Calculate for recalculation-based logic, or redesign the task around the cells whose values are directly changed.
Does Worksheet_Change work when I paste multiple cells?
Yes. Excel can pass the full changed block in Target. Use a range intersection and loop through the relevant cells instead of assuming Target contains only one cell.
Can I put Worksheet_Change in a standard module?
No. Put it in the code module for the worksheet whose edits it should monitor. A normal macro in a standard module does not become a worksheet event merely because it has a similar name.
Why did the event stop after another macro ran?
A previous macro may have set Application.EnableEvents to False and failed to restore it. Check the setting in the Immediate window and add reliable cleanup to the macro that disables events.
Can Worksheet_Change run in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel to use its VBA event procedures.
Related
- Excel Shortcut Keys for the Next Sheet in a Workbook
- Excel Named Range Data Validation List: Setup and Fixes
- Excel Named Range in a Drop-Down List: How to Set It Up
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Dictionary: How to Create and Use OneYes. In VBA, a dictionary is a key-value object that lets you store a value under a unique…
- VBA Copy PasteSpecial: Values, Formats, and MoreIn Excel VBA, copy a range and call PasteSpecial on the destination to paste only values, formats, formulas,…
- Excel VBA AutoFit: Resize Rows and Columns AutomaticallyIn Excel VBA, use the AutoFit method on the rows or columns you want to size. For example,…
- Easy Macro Recorder in Excel: How to Record and Use OneYes. Microsoft Excel for Microsoft 365 includes a built-in macro recorder: choose Developer > Record Macro, perform the…
- VBA Input Box for Password: Masking and Safer OptionsVBA’s built-in InputBox cannot mask a password: characters appear as the user types. To show dots or asterisks…
- Excel VBA Date Number Format: How to Set ItIn Excel VBA, format a cell or range as a date by setting its NumberFormat property, for example:…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.