How to Fix Office Scripts Recording Errors When Filtering Excel Rows
Question details
Users experience script execution failures when using the Office Scripts recorder to automate filtering or hiding rows based on formula results.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Automating spreadsheet tasks by recording row filtering or hiding actions based on dynamic formula results.
- Observed behavior
- The generated Office Script fails to execute, returning an error such as "Cannot read properties of undefined (reading greaterOrEqual)."
Before manually editing your scripts, ensure your Excel workbook is saved and create a backup copy of your data to prevent accidental loss during script testing.
Manually Code Range and Row Operations
Bypass the limitations of the Action Recorder by writing custom TypeScript code to handle your filtering logic.
The built-in Office Scripts Action Recorder sometimes struggles to properly translate dynamic interactions, like filtering based on formula values, into valid code. Manually defining the ranges and applying filters in the Code Editor is required.
Navigate to the Automate tab in the Excel ribbon and select your script to open the Code Editor pane.
Find the auto-generated lines causing the 'Cannot read properties of undefined' error, which are typically located near the range filtering or row hiding actions.
Replace the recorded steps with custom TypeScript code. Use standard methods like `Range.applyFilter` and clearly define the filter criteria instead of relying on the recorded dynamic actions.
Click Save, then run the updated script against a sample dataset to verify that the rows are filtered correctly without throwing errors.

Consult the Microsoft Power Automate Community
Since advanced Office Scripts issues are complex, seeking help in dedicated developer communities is highly effective.
Try WPS Office for Seamless Spreadsheet Automation
While Microsoft Excel relies on Office Scripts for web-based automation, WPS Office offers powerful desktop-level JS Macros and VBA support to easily automate row filtering and data processing tasks for free.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your computer.
- 2. Open Your Spreadsheet: Launch WPS Spreadsheets and open your existing Excel (.xlsx) file directly.
- 3. Utilize JS Macros or VBA: Navigate to the Tools tab to access the Macro editor, where you can write and execute traditional scripts to automate your workflow without web dependency errors.

Frequently Asked Questions
Why does the Office Scripts recorder fail when filtering rows?
The Action Recorder in Excel captures user interface actions but struggles to translate dynamic dependencies—such as filtering rows based on real-time formula results—into flawless TypeScript code. This often leads to 'undefined property' errors when the script runs.
How do I fix the 'Cannot read properties of undefined' error in Office Scripts?
This error occurs because the script attempts to interact with an object or property that has not been properly initialized. To fix it, open the Code Editor and manually define the range object explicitly before applying the filter.
Can I use standard VBA instead of Office Scripts for filtering?
Yes, VBA is a highly reliable alternative for automating complex tasks in desktop spreadsheet applications. While Office Scripts are tailored for Excel on the web and Power Automate, VBA or JS Macros are often more robust for intricate local row operations.




