Excel VBA: Trigger a Macro When a Cell Value Changes

VBA & macros · Updated November 19, 2026

Yes. In Excel for Microsoft 365 on Windows, put a Worksheet_Change event procedure in the worksheet’s code module to run VBA when a user edits or pastes values into that sheet. Check the changed-cell range with Intersect so the code runs only for the cells you care about.

What the Worksheet_Change event does

Worksheet_Change is an Excel event: Excel calls it automatically after a cell or range on that worksheet changes. Its Target argument identifies the changed cell or cells. That makes it useful for actions such as adding a timestamp, validating an entry, updating a related cell, or calling another macro.

The event responds to edits, pasted values, and many other direct changes to cell contents. It is not a general “anything on the sheet changed” notification. In particular, a formula recalculating to a different result does not by itself fire Worksheet_Change. That distinction matters when the cell you are watching contains a formula rather than a manually entered value.

There is also a workbook-level event, Workbook_SheetChange, which can respond to changes across worksheets. For a single-sheet task, the worksheet event is usually simpler and less likely to affect unrelated parts of the workbook.

Put the event code in the worksheet module

An event procedure must be stored in the code module for the sheet it watches. Putting Worksheet_Change in a standard module, or in the code module for a different sheet, will not make it respond to edits on the intended worksheet. The procedure name and its event signature must also be exact.

  1. Open the workbook in the desktop version of Excel and save a backup copy first.
  2. Right-click the tab for the worksheet you want to monitor and select View Code. This opens that sheet’s module in the Visual Basic Editor.
  3. Paste the event procedure into the code window. Replace the example range or action as needed.
  4. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm), close and reopen it if needed, and enable macros only if you trust the file and its source.

On Windows, Alt+F11 opens or switches to the Visual Basic Editor; the worksheet tab’s View Code command is a direct route to the correct module. On a Mac, the editor and worksheet events are available in desktop Excel too, but the shortcut can depend on the keyboard and function-key settings. Excel for the web does not run VBA macros; use desktop Excel to run or edit this code.

Example: run code when a watched cell changes

This example watches cells D2:D100. When one or more of those cells changes, it writes the current date and time in column E on the same row. The intersection check prevents edits elsewhere on the sheet from triggering the action. It also handles a multi-cell paste rather than assuming that Target is always one cell.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim watched As Range
    Dim changed As Range
    Dim cell As Range
    Dim priorEvents As Boolean

    ' Remember the existing event setting so it can be restored.
    priorEvents = Application.EnableEvents
    On Error GoTo HandleError

    Set watched = Me.Range("D2:D100")
    Set changed = Intersect(Target, watched)

    ' Leave immediately when the edit is outside the watched range.
    If changed Is Nothing Then Exit Sub

    ' Avoid triggering another event while writing timestamps.
    Application.EnableEvents = False
    For Each cell In changed.Cells
        Me.Cells(cell.Row, "E").Value = Now
    Next cell

CleanExit:
    Application.EnableEvents = priorEvents
    Exit Sub

HandleError:
    MsgBox "The change handler stopped: " & Err.Description, vbExclamation
    Resume CleanExit
End Sub

In actual VBA, the error-message line uses the ampersand operator followed by Err.Description; the & shown in HTML represents that character. The code restores the prior event setting even if the timestamp write encounters an error. If you do not need a timestamp, replace the loop’s action with your own code. For example, it can call a separate procedure in a standard module, provided that procedure is accessible and is written to handle the cells passed to it.

Change Me.Range("D2:D100") to the address you want to watch. Me refers to the worksheet containing this event code, which helps avoid accidentally pointing the event at another sheet. The timestamp is a fixed value written at the moment the handler runs; it is not a formula that continually updates.

Why event code disables events temporarily

When VBA writes to a cell, that write can cause another change event. If the handler writes into its own watched range, it can call itself repeatedly. Setting Application.EnableEvents to False during the write prevents that chain of event calls. Restoring the previous setting is important: if events are left disabled, other event procedures in the workbook may stop responding too.

Keep the event’s action focused and reasonably quick. A handler that recalculates large ranges, opens several files, or changes many sheets can make ordinary editing feel slow because the work happens as part of the edit. For lengthy work, consider having the event validate the change or schedule a more deliberate action instead of doing a large task on every keystroke or paste.

Formula results and recalculation are different

A common misconception is that Worksheet_Change fires whenever a displayed value changes. It does not: it fires when cells are changed directly, not merely because formulas recalculate. For example, if D2 contains a formula based on A2, changing A2 may change the displayed result in D2, but the change event is associated with the edited input cell, not the formula result changing.

If the task depends on a formula result, a Worksheet_Calculate event may be more appropriate. It runs when the worksheet recalculates, but it does not provide a changed-cell Target in the same way. Code generally needs to compare the relevant calculated result with a previously stored value to determine whether it actually changed. Take care not to make a calculation event perform edits that cause repeated recalculation.

For an event that should respond to a user changing an input cell that feeds a formula, watch the input cell with Worksheet_Change instead. This is often simpler and more predictable than monitoring the formula output.

Editing, pasting, and multiple changed cells

Target can contain multiple cells, such as when a user pastes a block of data. Code that assumes Target.Value is a single value may fail or behave unexpectedly for a multi-cell paste. The example uses Intersect and loops through each matching cell, so it can apply its timestamp action to every changed cell within D2:D100.

Choose how a bulk paste should behave before writing the macro. You might want to handle every affected row, reject a paste that contains invalid entries, or process the pasted range as a unit. If you only want to react when exactly one cell changes, test Target.CountLarge and exit for larger ranges—but remember that this deliberately ignores multi-cell edits and pastes.

For data validation, event code should usually inspect the new value and give the user a clear response. Avoid relying on Application.Undo as a general rollback strategy: VBA actions and undo behavior have limitations, and running a macro can clear Excel’s normal undo history.

Common problems and how to diagnose them

  • Nothing happens: Confirm that the code is in the correct sheet module, that the procedure is named Worksheet_Change, that the edit intersects the watched range, and that macros are enabled in desktop Excel.
  • The code works once, then stops: Check whether an earlier macro left Application.EnableEvents set to False. Restore it in the Immediate window with Application.EnableEvents = True, or close and reopen the workbook if appropriate. Do not leave events disabled as a workaround.
  • Typing works but a formula update does not: That is expected for a formula result. Watch the input cell or use a calculation event with a comparison strategy.
  • A paste causes an error: Make sure the code accounts for a multi-cell Target, as in the loop example, and that every affected row is safe to process.
  • The macro runs on the wrong sheet: Move the procedure into the intended sheet module and use Me for references to that sheet.
  • Excel seems to have stopped firing events: Another procedure may have disabled events and then stopped before restoring them. Add error handling that restores the previous setting, and test code on a copy of the workbook.

When debugging, place a breakpoint inside the event procedure and make one controlled edit in the watched range. The Visual Basic Editor can then show whether the procedure ran and what range Target represents. Remove breakpoints or resume execution when finished; code paused in the editor will not behave like an ordinary completed event.

Workbook events and non-VBA alternatives

Use Worksheet_Change when one sheet has a clear input range and should perform an action immediately. Use Workbook_SheetChange when the same kind of response is needed across multiple sheets; that event belongs in the ThisWorkbook module and includes a sheet argument as well as the changed range. A broader event should filter both the sheet and range so it does not run unnecessarily.

If the goal is only to flag unusual values visually, Conditional Formatting is simpler and does not require macros. If the goal is to recalculate a result, a worksheet formula may be more transparent than VBA. For automated workflows beyond desktop Excel, Power Automate or Office Scripts may be relevant, but their availability and capabilities differ from VBA and they are not drop-in replacements for a worksheet event.

Frequently Asked Questions

Can I trigger a macro when a specific cell changes?
Yes. Put Worksheet_Change in that cell’s worksheet module and use Intersect(Target, Me.Range("A1")) to restrict the action to A1. Use the actual address of the cell you want to monitor.

Does Worksheet_Change detect a formula result changing?
No. It detects direct changes to cell contents, not a result changing only because of recalculation. Watch the formula’s input cell or consider Worksheet_Calculate with code that compares the result to its previous value.

Can I use this event for a range of cells?
Yes. Pass a range such as D2:D100 to Intersect. Since a paste can change many cells at once, loop through the intersecting cells or deliberately decide how to process a multi-cell change.

Can a macro trigger itself?
It can if the event procedure writes to cells in a way that causes another event. Temporarily disable events around the write, then restore the previous setting in all normal and error paths.

Will the macro work in Excel for the web?
No. Excel for the web does not run VBA. Open the macro-enabled workbook in desktop Excel for Windows or Mac to use its VBA event procedures.

Save safely and test the behavior

Save a separate copy before running a macro: VBA actions cannot be undone with Ctrl+Z, and a macro may alter more cells than intended if its range check is wrong. Test with a few ordinary edits, a multi-cell paste, and a change outside the watched range. Confirm that the timestamp or other action is correct and that unrelated edits do not trigger it.

Keep the workbook in .xlsm format so its VBA project is preserved. Macro warnings are a security boundary, not a prompt to enable every file indiscriminately; only allow code from a source you trust. If the workbook is shared, tell users which cells trigger the event and what it changes, especially if it writes values into adjacent columns.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.