How to Create an Excel Macro to Require Cells After a Row is Started
Question details
The user needs a method to enforce mandatory data entry in specific columns whenever any cell in that same row is populated.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating a spreadsheet form where completing one cell triggers a requirement to fill out the rest of the required fields in that specific row.
- Observed behavior
- Currently, users can fill out partial rows without receiving any warning. The goal is to trigger an error identifying blank mandatory fields when a row is partially filled.
Before writing your macro, ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled the Developer tab to access the VBA Editor.
Implement a Worksheet_Change Event for Real-Time Validation
This macro automatically checks for empty required cells in real-time as soon as data is entered into a monitored row.
Unlike basic cell locking, a Worksheet_Change event actively monitors user input. When a user enters data in a monitored range (e.g., Columns A through H), the macro scans the row and prompts the user if mandatory fields are missing.
Using this method guarantees that users are immediately notified of incomplete forms without needing to manually click a validation button.
Press Alt + F11 to launch the Visual Basic for Applications (VBA) Editor.
In the Project Explorer panel on the left, double-click the specific worksheet (e.g., Sheet1) where you want the validation to occur.
Select 'Worksheet' from the top-left dropdown and 'Change' from the top-right dropdown to generate the Private Sub Worksheet_Change(ByVal Target As Range) framework.
Add code to check if the Target.Row falls within your form range (e.g., rows 1 to 100). Write a loop or conditional statements to check if IsEmpty(Cells(Target.Row, colIndex)) is true for required columns.
Include a MsgBox command within your logic to display a customized error alert indicating exactly which cells or columns are missing data.

Use a Form-Control Validation Macro
If real-time alerts are too disruptive, you can attach a validation macro to a 'Submit' button to check all rows at once.
Easily Write and Execute Macros with WPS Spreadsheet
WPS Office provides robust built-in support for VBA macros, allowing you to create complex data validation rules, custom events, and interactive forms securely and efficiently.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your existing form or create a new document.
- 2. Access the Developer Tools: Navigate to the 'Tools' tab and click on 'Developer' to access the built-in VBA editor.
- 3. Insert Your Macro Code: Double-click your active worksheet in the Project window and paste your Worksheet_Change event code.
- 4. Save as Macro-Enabled: Go to Menu > Save As, and select the Macro-Enabled Workbook (.xlsm) format to preserve your functionality securely.

Frequently Asked Questions
Can I use Data Validation instead of a Macro to require cells?
Standard Data Validation can restrict what type of data is typed into a cell, but it cannot force a user to enter data into an empty cell based on another cell's value. A VBA macro or Worksheet event is required to actively check for and enforce completion of blank cells.
Why doesn't locking cells enforce data entry?
The 'Locked' property in Excel simply prevents a cell from being edited or modified when the worksheet is protected. It does not validate whether the cell is blank or mandate that data must be entered before saving.
How do I apply the macro to specific columns only, like A through H?
In your VBA event code, use the 'Intersect' method to check if the modified cell (Target) falls within your desired range (e.g., Range("A:H")). If it does not intersect, the macro will simply exit without running the validation logic.




