VBA & Macro Problems

Prevent an Excel VBA Macro from Running After a Cell Is Filled

Muhammad TalhaMuhammad Talha Dec 2, 2026 869 views

Question details

Add a condition that prevents an Excel VBA macro from continuing when a control cell contains a value or comment.

Prevent an Excel VBA Macro from Running After a Cell Is Filled
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A macro should run only while a designated control cell is empty.
Observed behavior
The user wants the macro to stop running after a value or comment is added to the control cell.
Before you start

Identify the control cell and worksheet, and decide whether the macro should check the cell value, a comment, or both. Open the VBA editor with Alt+F11, or use Developer > Visual Basic.

Solution 1Recommended

Exit the Macro When the Control Cell Has a Value

Use an early exit to stop the macro before its main code runs if the control cell is filled.

1
Open the macro

In the VBA editor, find the macro in its module and place the condition immediately after the Sub declaration.

2
Add the value check

For cell A1 on a specific worksheet, add: If ThisWorkbook.Worksheets("Sheet1").Range("A1").Value <> "" Then Exit Sub Replace Sheet1 and A1 with your worksheet and control cell.

3
Test the macro

Run the macro with A1 empty, then enter a value in A1 and run it again. The macro should exit before executing the remaining code when A1 is filled.

Value checks and comments: This condition checks the cell value, not whether the cell has a comment. A formula that returns an empty string also passes the value check.
Free Microsoft Office alternative

Work with Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. Its Microsoft Office format compatibility can make moving everyday files straightforward, although it does not fix Excel VBA behavior and macro compatibility may vary.

Open and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface to inspect control-cell valuesMove everyday Office documents between compatible applicationsWork with a free, lightweight Office suite
microsoft office alternative - wps office

Frequently Asked Questions

How do I check a control cell on a specific worksheet?

Use a qualified reference such as ThisWorkbook.Worksheets("Sheet1").Range("A1") instead of ActiveSheet.Range("A1"). Replace the worksheet name and cell address as needed.

Does a cell value check also detect a comment?

No. Range("A1").Value checks the cell's value. Check the Comment object for a legacy note and, in supported Excel versions, CommentThreaded for a threaded comment.

Why does my Worksheet_Change macro run repeatedly?

The event can run again when its code changes a cell. Set Application.EnableEvents to False before automated changes and restore it to True in a cleanup section, including when an error occurs.

Will adding a comment trigger Worksheet_Change?

No. Worksheet_Change responds to cell value changes, not the act of adding or editing a comment. Check the comment when the macro runs through another trigger.