Fix Excel Office Script SortOrientation Rows Not Working
Question details
The user needs a solution for an Excel Office Script that fails to sort rows using the SortOrientation.rows property.

- 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.
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.
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.
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.
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.
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.

Consult the Microsoft Office Development Community
If modifying the script range and parameters does not resolve the issue, seeking help from specialized Office Script developers is recommended.
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. Visit the official website: Navigate to the official WPS Office website to download the installer.
- 2. Download and install: Click the 'Download WPS Office Free' button and follow the on-screen instructions to install the suite.
- 3. Open your spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to manage and sort your data seamlessly.

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.




