logo
search
VBA & Macro Problems

How to Fix Excel Office Script Not Sorting by Fill Color

John WilsonJohn Wilson Sep 30, 2026 869 views

Question details

The user needs to correctly automate sorting data by cell fill color using an Excel Office Script triggered by a button.

How to Fix Excel Office Script Not Sorting by Fill Color
Product
Microsoft Excel
Device & OS
not provided
Scenario
Running a recorded Office Script to move specific colored cells (e.g., red YES cells) to the bottom of a worksheet.
Observed behavior
The Office Script recorded from the 'Sort by Color' command fails to correctly move the colored cells to the bottom when executed via a button.
Before you start

Verify that your cell colors are applied as standard background fills, as Office Scripts may fail to recognize colors applied dynamically through Conditional Formatting.

Solution 1Recommended

Seek Support in the Microsoft Office Development Community

Because Office Scripts rely on TypeScript and specific Microsoft 365 environments, complex script failures are best addressed by Microsoft's dedicated developer community.

Recorded Office Scripts often struggle with dynamic ranges or specific color index translations. Consulting experts ensures your TypeScript logic is correctly modified to handle custom color sorting.

1
Gather your script details

Copy the exact code of your recorded Office Script, and note your expected sort order, specific fill-color details, and the platform (Excel for Web or Desktop) you are using.

2
Navigate to Microsoft Q&A

Open your web browser and go to the Office Development section of Microsoft Q&A, which actively handles Office Scripts troubleshooting.

3
Post your question

Create a new thread providing all your gathered details so the community can help correct the script's sorting logic.

Information: Including screenshots of your data structure in your forum post will significantly speed up the troubleshooting process.
Free Microsoft Office alternative

Try WPS Office for Seamless Macro and Data Automation

If Excel's Office Scripts are causing frustration, WPS Office offers a powerful, free alternative. With robust support for traditional VBA and modern JS Macros, you can easily automate sorting and data formatting without the steep learning curve.

  1. 1. Download and install: Get WPS Office for free from the official website and install it on your device.
  2. 2. Open your spreadsheet: Open your existing .xlsx or .xlsm file directly in WPS Spreadsheet with full formatting retained.
  3. 3. Automate your tasks: Use the built-in Macro editor to create reliable sorting scripts using JSA or VBA.
Free and lightweight Office suiteFully compatible with Microsoft Excel formats (.xlsx, .xlsm)Built-in support for VBA and JS MacrosIntuitive sorting, filtering, and data analysis tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does my recorded Office Script fail to sort by color?

Recorded scripts often hardcode specific ranges or fail to accurately capture color index values. Dynamic ranges or colors applied via conditional formatting usually require custom TypeScript code rather than simple macro recording.

Can I sort by cell color without using any scripts?

Yes. You can select your data range, go to the Data tab, click Sort, and change the 'Sort On' parameter to 'Cell Color'. From there, you can choose the color and dictate whether it appears at the top or bottom.

What is the difference between Office Scripts and VBA?

Office Scripts are based on TypeScript and are primarily designed for Excel on the Web to automate tasks across cloud platforms. VBA (Visual Basic for Applications) is the traditional desktop macro language for Office applications.