logo
search
VBA & Macro Problems

How to Fix Office Scripts Recording Errors When Filtering Excel Rows

Phi Hung VoPhi Hung Vo Oct 10, 2026 871 views

Question details

Users experience script execution failures when using the Office Scripts recorder to automate filtering or hiding rows based on formula results.

Fix Office Scripts Recording Errors When Filtering Excel Rows
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 you start

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.

Solution 1Recommended

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.

1
Open the Code Editor

Navigate to the Automate tab in the Excel ribbon and select your script to open the Code Editor pane.

2
Locate the problematic code

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.

3
Rewrite the filtering logic

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.

4
Save and test the script

Click Save, then run the updated script against a sample dataset to verify that the rows are filtered correctly without throwing errors.

Manually Code Range and Row Operations
Coding Prerequisites: You will need a basic understanding of TypeScript and the Excel JavaScript API to successfully modify and troubleshoot the auto-generated Office Scripts.
Free Microsoft Office alternative

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. 1. Download and Install: Get WPS Office for free from the official website and install it on your computer.
  2. 2. Open Your Spreadsheet: Launch WPS Spreadsheets and open your existing Excel (.xlsx) file directly.
  3. 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.
Free, lightweight, and fast installation across multiple platformsExcellent compatibility with Microsoft Excel formats (.xlsx, .xls) and existing macrosRobust built-in JS Macro and VBA support for automating complex data filteringFamiliar ribbon interface requiring minimal learning curve for seamless migration
microsoft office alternative - wps office

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.