Fix Excel Office Scripts Data Validation Errors and Dependent Drop-Downs
Question details
Troubleshoot an Office Scripts error when applying list validation from a reference worksheet and create dependent drop-down lists.

- Product
- Microsoft Excel Office Scripts
- Device & OS
- not provided
- Scenario
- A script applies list data validation to cells using values stored on a reference worksheet.
- Observed behavior
- The script reports “Cannot set properties of undefined” while applying data validation.
Open the workbook in Excel and confirm that the target worksheet, reference worksheet, and source cells exist. Identify the target column and check whether the script calculates its position using zero-based indexes.
Check the target range and apply validation through its DataValidation object
Use this approach when the script reports an undefined-property error while setting a validation rule.
Excel Office Scripts uses zero-based row and column indexes. A missing header or an extra subtraction can cause the script to select the wrong column or fail to create the intended range.
In Excel, open Automate and select the script. Check the worksheet names and the code that assigns the target range to next.
Check that material_index is not -1 before using it. If the index comes from getColumnIndex(), use it as a zero-based index and do not subtract 1.
Select the source cells on the reference worksheet, then use Formulas > Define Name to create a workbook-level name such as MaterialList. Confirm that it refers to the intended cells.
After confirming that next is a valid target range, call next.getDataValidation().setRule({ list: { inCellDropDown: true, source: "=MaterialList" } }). Run the script from Automate and test a target cell.

Create dependent drop-downs with named ranges
Use named lists and an INDIRECT formula when the choices in one column should depend on a selection in another.
Work with spreadsheet drop-downs in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. It supports Excel formats for easier migration, but it does not fix or run Microsoft Office Scripts.

Frequently Asked Questions
Why does my Office Script report an undefined-property error?
The target range or an object used to calculate it may be undefined. In Automate, check the worksheet names, verify that a header search did not return -1, and confirm that next is assigned a valid range before calling getDataValidation().
Does getColumnIndex() start at 0 or 1?
It returns a zero-based column index: column A is 0 and column B is 1. Use that value consistently when calculating ranges.
How can a validation list use cells on another worksheet?
Select the source cells and create a workbook-level name through Formulas > Define Name. Then use the name as the list source, for example =MaterialList.
Why is my dependent drop-down empty?
Check that the category cell contains a value matching a defined name and that the name refers to the intended source cells. For a target in C2, verify that the validation source references B2, such as =INDIRECT($B2).
Can WPS Office run my Excel Office Script?
No. Office Scripts is a Microsoft Excel automation feature. WPS Office can be used as an alternative for spreadsheet editing and data validation, but it does not run or repair the script.




