VBA & Macro Problems

Fix Excel Office Scripts Data Validation Errors and Dependent Drop-Downs

Algirdas JasaitisAlgirdas Jasaitis Dec 2, 2026 868 views

Question details

Troubleshoot an Office Scripts error when applying list validation from a reference worksheet and create dependent drop-down lists.

Fix Excel Office Scripts Data Validation Errors and Dependent Drop-Downs
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.
Before you start

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.

Solution 1Recommended

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.

1
Inspect the script

In Excel, open Automate and select the script. Check the worksheet names and the code that assigns the target range to next.

2
Validate the column index

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.

3
Define a list source

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.

4
Set the rule on the range

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.

Check the target range and apply validation through its DataValidation object
Check the source separately: An undefined target range and an invalid list source are different problems. Using a workbook-level named range avoids relying on a direct cross-sheet reference in the validation formula.
Free Microsoft Office alternative

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.

Create spreadsheet drop-down lists using data validationOpen and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface for everyday workMove existing spreadsheets to a lightweight office suite
microsoft office alternative - wps office

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.