Prevent an Excel VBA Macro from Running After a Cell Is Filled
Question details
Add a condition that prevents an Excel VBA macro from continuing when a control cell contains a value or comment.

- 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.
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.
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.
In the VBA editor, find the macro in its module and place the condition immediately after the Sub declaration.
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.
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.
Guard a Worksheet Change Event Against Recursion
Use this approach when the macro runs from Worksheet_Change and makes changes to cells itself.
Exit the Macro When the Control Cell Has a Comment
Use a separate comment check when the control cell must have neither a value nor a comment.
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.

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.




