Excel’s Worksheet_Change event is a VBA procedure that runs when cells on a particular worksheet are changed, such as when someone types, pastes, or deletes a value. To use it, open that worksheet’s code module in the Visual Basic Editor and add a procedure named Worksheet_Change; it does not run when a formula’s result changes only because Excel recalculated.
What the Worksheet Change Event Does
The event gives VBA a way to respond to edits as they happen. Common uses include recording a timestamp beside an updated entry, checking that an input meets a rule, updating a related cell, or notifying a user when a watched range changes. It belongs to one worksheet, so an event procedure placed in the code module for a particular sheet responds to changes on that sheet, not every sheet in the workbook.
Excel passes the event a parameter named Target, which is a Range representing the cell or cells that changed. If a person edits one cell, Target is usually one cell. If they paste a block, clear several cells, or fill a range, Target can include many cells. Code should account for that possibility rather than assuming a single-cell edit.
The event is a desktop Excel VBA feature. Excel for the web can open a macro-enabled workbook, but it does not run VBA macros or worksheet event procedures. On Mac, Excel desktop supports VBA, although keyboard shortcuts and some interface labels can vary by keyboard and release.
When It Runs—and When It Does Not
Worksheet_Change runs after cells on the worksheet are changed, including edits made by a user and changes made through some external links. Typical triggers include typing a value, pasting content, deleting a cell’s contents, or changing a cell through VBA while events are enabled. It is not a general notification for every visual or calculation change in a workbook.
A formula recalculating is the most important exception. If A1 contains a formula and its displayed result changes because a precedent was edited, A1 itself was not edited; the change event does not fire for A1 just because its result changed. If your goal is to react to recalculation, investigate the worksheet’s Worksheet_Calculate event instead. That event does not provide a Target range, so code often needs to compare calculated results with stored prior values.
Other actions have their own events. Selecting a different cell is associated with Worksheet_SelectionChange, not Worksheet_Change. Opening a workbook, activating a sheet, or changing a chart also calls for a different event or approach. Choosing the event that matches the action avoids code that appears not to work simply because it is listening for the wrong thing.
How to Add the Event in Excel for Windows
Put the procedure in the worksheet’s own code module. A standard module, such as Module1, is useful for ordinary macros, but Excel will not treat a procedure there as that sheet’s built-in change event. Before adding code, save a backup copy of the workbook. A workbook containing VBA generally needs a macro-enabled format such as .xlsm; saving it as .xlsx removes its VBA project.
- If the Developer tab is not visible, go to File > Options > Customize Ribbon, select Developer in the list of main tabs, and choose OK.
- Choose Developer > Visual Basic, or press Alt+F11 on Windows, to open the Visual Basic Editor.
- In Project Explorer, find the workbook, expand Microsoft Excel Objects, and double-click the sheet where edits should be detected. The object may be named, for example, Sheet1 (Orders).
- Paste the event procedure into that sheet’s code window, edit its watched range or actions as needed, and save the workbook as an Excel Macro-Enabled Workbook.
On Mac, open the Visual Basic Editor from the Developer tab or Excel’s macro/developer tools; Option+F11 is a common shortcut, and some keyboards require Fn as well. The editor’s project structure is similar, but ribbon customization and menu labels differ from Windows. VBA code must run in desktop Excel, not in the browser. Users may also need to allow macros for a trusted workbook under their organization’s security rules.
A Practical Example: Add a Timestamp
Suppose a sheet has entries in A2:A100 and you want column B to show when each entry was last changed. The following event monitors only that input range. It writes a fixed date and time into the same row in column B; if an input is cleared, it clears the corresponding timestamp. Paste it into the code module for the worksheet that contains the data.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim watchedRange As Range
Dim changedCells As Range
Dim changedCell As Range
Dim eventsWereEnabled As Boolean
Dim errorMessage As String
eventsWereEnabled = Application.EnableEvents
On Error GoTo ErrorHandler
Set watchedRange = Me.Range("A2:A100")
Set changedCells = Intersect(Target, watchedRange)
If changedCells Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each changedCell In changedCells.Cells
If Len(changedCell.Value2) > 0 Then
Me.Cells(changedCell.Row, "B").Value = Now
Else
Me.Cells(changedCell.Row, "B").ClearContents
End If
Next changedCell
GoTo CleanUp
ErrorHandler:
errorMessage = Err.Description
Resume CleanUp
CleanUp:
Application.EnableEvents = eventsWereEnabled
If Len(errorMessage) > 0 Then
MsgBox "The change event could not finish: " & errorMessage, vbExclamation
End If
End Sub
Intersect limits the work to edits that overlap A2:A100, so an unrelated change elsewhere on the sheet exits without action. The loop handles a multi-cell paste one cell at a time. Now records the computer’s current date and time as a value; it is not a live clock formula, and it will not continually update. The sample is illustrative: adjust the watched range and destination column to fit the layout, and ensure the destination does not overlap the watched cells.
Handling Multiple Cells and Choosing a Scope
Bulk edits are a common source of fragile event code. A user can paste ten rows at once, and Target then represents the pasted range. A procedure that directly reads Target.Value as if it were one value may behave differently or fail when Target contains multiple cells. Use a loop over Target.Cells, or over the intersection with a watched range, when every changed cell needs individual treatment.
Use Intersect(Target, Me.Range("D2:D500")) when only one input area matters. For several separate input areas, combine ranges with Union and intersect Target with that combined range. If the event should respond to any edit on the sheet, a range filter may not be needed, but it is usually wise to rule out headers, output cells, and areas where changes should have no effect.
A worksheet event is best when behavior is specific to one sheet. If the same rule must apply across many sheets, a workbook-level event such as Workbook_SheetChange in the ThisWorkbook module may be more suitable. That broader event receives both the changed sheet and the Target range, so the code needs to check which sheets are in scope. Avoid duplicating similar code across numerous sheet modules unless the rules genuinely differ.
Preventing Recursive Events and Handling Errors
An event can cause itself to run again. For example, the timestamp sample writes to column B; without safeguards, that write can trigger another change event. Setting Application.EnableEvents to False before the programmatic edit prevents Excel events from firing during that operation. The code then restores the previous setting rather than assuming events were enabled beforehand.
Restoring the setting matters because a VBA error can interrupt normal execution. If a macro leaves events disabled, other event procedures in the current Excel application may stop responding until events are turned back on. An error-handling path, as in the sample, gives the code a chance to restore the setting and report a problem. Keep the disabled period as short as practical, and do not turn events off for unrelated work.
When debugging, check that the event procedure is in the correct sheet module, that the edited cells overlap the range it watches, and that Application.EnableEvents is True. The event is named and declared in a particular way; renaming it or placing it in a regular module prevents Excel from recognizing it as the worksheet event. Also check that the workbook was saved in a macro-capable format and that macros are permitted to run.
Common Misunderstandings and Troubleshooting
One frequent misconception is that a formula’s displayed change must trigger the event. It does not: the event tracks cell edits, not every change in a cell’s calculated result. Another is that changing the active cell counts as a worksheet change; selection has its own event. These distinctions help determine whether a change event, calculate event, selection event, or a formula-based solution is appropriate.
If a procedure appears to do nothing, use this checklist:
- Confirm that the procedure is in the code module for the worksheet being edited, not a standard module.
- Confirm that the changed cells intersect the range in the code and that the code has not exited early.
- Check whether an earlier macro left
Application.EnableEventsset to False. In the Immediate window, an authorized VBA user can inspect or reset it with? Application.EnableEventsandApplication.EnableEvents = True. - Confirm that the workbook is open in desktop Excel and that macros have not been blocked by security settings.
- Test both a single-cell edit and a multi-cell paste; those produce different Target sizes.
Events can also be bypassed by code that deliberately disables events, and a procedure will not retroactively respond to edits made before it was installed. If an event-driven process is essential, document what it does and provide a manual recovery method for cases where macros are disabled. Save a copy before running or modifying VBA: macro actions generally cannot be undone with Ctrl+Z, and the same limitation applies to Mac’s Undo shortcut.
Frequently Asked Questions
Does Worksheet_Change run when a formula recalculates?
No. It runs when a cell is edited, not merely when its formula returns a different result. For recalculation-related work, consider Worksheet_Calculate and design a way to identify which results changed.
Where do I paste Worksheet_Change code?
Paste it into the code module for the specific worksheet, found under Microsoft Excel Objects in the Visual Basic Editor. A procedure with that name in a standard module does not act as that worksheet’s event handler.
Can Worksheet_Change handle a pasted range?
Yes. Target can contain multiple cells, so write code that checks the range and loops through affected cells where needed. Do not assume a paste or delete operation will always affect just one cell.
Why has my change event stopped working?
Common causes include code in the wrong module, an edit outside the watched range, macros being blocked, or Application.EnableEvents being left False by another macro. Formula recalculation alone does not trigger this event.
Does the event work in Excel for the web?
No. Excel for the web does not execute VBA event procedures. Use desktop Excel for VBA-based behavior, or consider a non-VBA option if the workbook must operate in a browser.
Related
- Freeze Panes in Excel: Keep Rows and Columns Visible
- Find Duplicates in Excel: A Practical Step-by-Step Guide
- How to Find External Links in Excel and Check Their Sources
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Check Whether a Worksheet ExistsTo check whether a worksheet exists in Excel VBA, loop through the target workbook’s Worksheets collection and compare…
- Excel VBA AutoFilter: Examples, Criteria, and FixesExcel VBA AutoFilter filters a worksheet range or Excel table by applying criteria to one or more columns.…
- Excel VBA: Find the Last Row with Data in a ColumnTo find the last populated row in column A with Excel VBA, use ws.Cells(ws.Rows.Count, "A").End(xlUp).Row, where ws is…
- Assign a Macro to a UserForm Command Button in ExcelIn Excel for Microsoft 365 on Windows, you do not assign a UserForm command button through the worksheet’s…
- Excel VBA Lookup: Find Matching Data with CodeAn Excel VBA lookup searches a range for a value and returns related information, such as a product…
- Excel VBA Delete a Workbook: Safe Methods and CodeYes. Excel VBA can delete a workbook file from disk, but the workbook must be closed first: Workbook.Close…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.