logo
search
Others

Fix Excel Office Script SortOrientation Rows Not Working

Rana GarciaRana Garcia Oct 7, 2026 868 views

Question details

The user needs a solution for an Excel Office Script that fails to sort rows using the SortOrientation.rows property.

Fix Excel Office Script SortOrientation Rows Not Working
Product
Microsoft Excel
Device & OS
not provided
Scenario
Running or recording an Office Script to sort data horizontally across rows in an Excel spreadsheet.
Observed behavior
Excel displays an 'Unable to record this action' error in both the web and desktop versions, and the script fails to sort the selected range.
Before you start

Ensure your Excel workbook is saved to OneDrive or SharePoint, as Office Scripts are primarily supported in these cloud environments, and verify you have appropriate editing permissions.

Solution 1Recommended

Expand the Target Range and Use SortFields

Modifying the target range size and explicitly defining the sort order using the SortFields object can resolve script execution errors.

Often, the Action Recorder struggles to process small or highly specific range selections when sorting horizontally. Manually updating your TypeScript code to use the SortFields object ensures the sort logic is explicitly defined and properly interpreted by Excel.

1
Modify the target range

Test the sort action against a significantly larger range, such as 'G4:L10', in your script to determine whether a narrow selected range is causing the interpretation error.

2
Update to use SortFields

Instead of passing an array directly to the apply method, update your code to utilize the 'SortFields' object to explicitly specify the sort order and orientation.

3
Run the script

Save the updated Office Script in the Code Editor and run it again to verify if the 'Unable to record this action' error is cleared.

Expand the Target Range and Use SortFields
Tip: Defining precise parameters using the SortFields object provides better script stability and prevents the Action Recorder from failing to translate your commands.
Free Microsoft Office alternative

Try WPS Office for Seamless Spreadsheet Management

If you are dealing with complex Microsoft Excel script limitations or simply need a reliable, lightweight spreadsheet tool, WPS Office is an excellent free alternative. It offers full compatibility with Microsoft Office file formats and features an intuitive, familiar interface for your daily data processing tasks.

  1. 1. Visit the official website: Navigate to the official WPS Office website to download the installer.
  2. 2. Download and install: Click the 'Download WPS Office Free' button and follow the on-screen instructions to install the suite.
  3. 3. Open your spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to manage and sort your data seamlessly.
Fully compatible with Microsoft Excel (.xlsx, .xls, .csv) formats.Lightweight and fast installation, saving your system resources.Familiar user interface ensuring a seamless migration from Microsoft Office.Rich built-in formulas and sorting tools for efficient data analysis without complex scripting.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the Excel Action Recorder show 'Unable to record this action'?

This error typically occurs when the Action Recorder encounters a step it cannot automatically translate into TypeScript, such as unsupported formatting, overly complex range selections, or specific API limitations.

How do I sort data horizontally using Office Scripts?

You can sort horizontally from left to right by setting the 'SortOrientation.rows' property in your script. Ensure that your range and 'SortFields' are accurately defined to avoid execution errors.

Are Excel Office Scripts the same as VBA macros?

No, they are fundamentally different. Office Scripts are written in TypeScript and are optimized for Excel on the web and cloud-stored workbooks, whereas VBA is a legacy macro language primarily tied to the desktop versions of Excel.