Fix Excel VBA Input Error After Inserting Rows and Copying Cells
Question details
The user experiences a custom input error that prevents data entry in specific cells after running an Excel VBA macro designed to insert rows and copy formulas.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Running a modified VBA macro to insert rows and copy cell formulas within a protected workbook.
- Observed behavior
- A custom error message blocks data entry in other cells, which is caused by the macro unexpectedly interacting with or inheriting existing data validation rules.
Ensure you have the correct workbook password to temporarily unprotect the sheet, as you cannot check or modify data validation rules on locked cells within a protected worksheet.
Check and Adjust Data Validation Rules
Identify and modify the data validation settings that are triggering the custom error when the VBA script modifies the cells.
When a VBA macro inserts rows or copies cells, it can inherit or duplicate existing data validation rules from adjacent rows. If the macro or user later attempts to input data that violates these copied rules, Excel will throw a custom input error and block the action.
Navigate to the 'Review' tab on the ribbon and click 'Unprotect Sheet'. Enter the password if prompted, allowing you to make structural changes.
Highlight the specific cells or the newly inserted row where the input error is occurring during data entry.
Go to the 'Data' tab and click on 'Data Validation' in the Data Tools group.
In the 'Settings' tab, check if there is an unintended rule applied. Switch to the 'Error Alert' tab to verify if the custom error message matches the one you are seeing.
Click 'Clear All' to remove the validation from the affected cells, or adjust the criteria so it accommodates the macro's output, then click 'OK'.

Manage VBA Macros and Data Validation Seamlessly in WPS Office
WPS Office provides robust support for VBA macros and complex data validation rules, allowing you to automate tasks and troubleshoot protected workbooks without compatibility issues.
- 1. Open your Workbook: Launch WPS Spreadsheets and open your macro-enabled workbook (.xlsm) to seamlessly load your scripts.
- 2. Manage Data Validation: Navigate to the 'Data' tab and click 'Validation' to easily configure, review, or clear problematic rules on your sheet.
- 3. Run VBA Macros: Go to the 'Developer' tab to access the built-in VBA Editor, debug your code, and run your macros smoothly.

Frequently Asked Questions
Why does inserting a row with VBA cause a validation error?
When VBA inserts a new row, Excel automatically inherits formatting and data validation rules from the row directly above it. If your macro tries to input data into the new row that violates this inherited rule, a custom input error is triggered.
How can I prevent VBA from copying data validation rules?
Instead of using a standard copy-and-paste method in your VBA script, use the PasteSpecial method. By specifying xlPasteValues or xlPasteFormulas, you ensure that only the data or formula is copied, leaving the problematic data validation rules behind.
Can a protected workbook block VBA macros?
Yes. If your VBA script attempts to modify locked cells or perform structural changes like inserting rows, it will fail. You must either have the macro temporarily unprotect the worksheet using 'ActiveSheet.Unprotect', or protect the sheet with 'UserInterfaceOnly:=True' to allow macros to run on locked sheets.




