VBA & Macro Problems

Fix Excel VBA Worksheet_Change Stack Overflow When Updating Cells

Kushani NimanthikaKushani Nimanthika Nov 18, 2026 870 views

Question details

Prevent a Worksheet_Change macro from causing an out-of-stack-space error while updating cells.

Fix Excel VBA Worksheet_Change Stack Overflow When Updating Cells
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet event responds to changes in C27 and C31 and also checks B37 before writing to H38.
Observed behavior
After the B37 check and H38 update are added, the macro raises run-time error 28, Out of stack space. B37 is formula-driven, so its recalculated value may not trigger Worksheet_Change.
Before you start

Open the workbook in Excel, press Alt+F11, and locate the affected worksheet's code module. Check which cells are edited directly, which contain formulas, and whether any relevant cells are merged.

Solution 1Recommended

Disable events while Worksheet_Change updates cells

Use this approach to stop writes such as the H38 update from recursively triggering Worksheet_Change.

Add the event guard to the existing Worksheet_Change procedure rather than creating a second procedure with the same name. Keep the existing business rules inside the guarded section.

1
Open the worksheet code

Press Alt+F11, then double-click the affected sheet under Microsoft Excel Objects in the VBA Project pane.

2
Filter the triggering cells

In the existing Worksheet_Change procedure, use Intersect to check Target against the cells that should trigger the logic, such as C27, C31, and C35 if C35 is edited directly. Include B37 only if it can also be changed directly; formula recalculation alone does not fire Worksheet_Change.

3
Guard the cell updates

Before the code that writes to H38 or other cells, set Application.EnableEvents = False. Add an error handler and a cleanup section that restores Application.EnableEvents = True on both normal and error exits.

4
Test each trigger

Return to the worksheet and edit C27, C31, and any other intended input cells. Confirm that H38 updates as expected and that later edits still trigger the event.

Disable events while Worksheet_Change updates cells
Restore events after an interrupted macro: If events remain disabled after a reset or interruption, open the VBA Immediate window with Ctrl+G, enter Application.EnableEvents = True, and press Enter.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easier to move everyday spreadsheet work. It does not fix an Excel VBA event error, and macro compatibility depends on the WPS version and configuration.

Open and edit common Excel formats, including XLSXUse a familiar spreadsheet interface for everyday cell and formula workMove routine spreadsheet tasks to a lightweight Office alternativeWork with spreadsheets for free
microsoft office alternative - wps office

Frequently Asked Questions

Why does writing to H38 cause error 28?

A write made inside Worksheet_Change can trigger the same event again, creating repeated calls until Excel runs out of stack space. Disable events before the write and restore them in a cleanup section.

Why doesn't Worksheet_Change run when B37's formula result changes?

Formula recalculation does not itself fire Worksheet_Change. Monitor a directly edited precedent such as C35 when appropriate, or use Worksheet_Calculate to detect a changed result.

How do I turn Excel events back on after stopping a macro?

In the VBA editor, press Ctrl+G to open the Immediate window, enter Application.EnableEvents = True, and press Enter.

Can merged cells affect the event logic?

Yes. Merged cells can affect which range is reported or where a value is stored. Check Home > Merge & Center and use the merged range's top-left cell when appropriate.