How to Return Sorted Row Numbers for Dynamic Array Values in Spreadsheet
Question details
The user needs a dynamic formula to return row numbers for spilled array values, sorted descending and grouped correctly for duplicate entries.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Sorting and extracting sequential row indexes from a dynamic spilled array range.
- Observed behavior
- Requires a formula setup that does not yield a #NAME? error and successfully processes dynamic array functions.
Verify that your spreadsheet software is updated to a version that natively supports dynamic array functions such as SORTBY, SEQUENCE, and the spilled range operator (#).
Use SORTBY, SEQUENCE, and RANK to Sort Spilled Row Numbers
Combine these dynamic array functions to automatically generate a sequence of row numbers based on the sorted rank of your data range.
By nesting the SEQUENCE and RANK functions inside SORTBY, you can dynamically assign row numbers to a spilled range. The SEQUENCE function counts the items and generates the numbers, while RANK provides the descending order and automatically groups duplicate values.
Locate the top-left cell where your dynamic data range begins (for example, cell J3). Ensure it has the spilled range operator (#) attached to reference the whole array.
Select an empty cell where you want the sorted row numbers to appear and type the formula: =SORTBY(SEQUENCE(COUNT(J3#)),RANK(J3#,J3#)).
Press Enter. The calculated row numbers will automatically spill down the column alongside your target array.

Easily Handle Dynamic Array Formulas with WPS Spreadsheet
WPS Spreadsheet fully supports advanced dynamic array functions like SORTBY, SEQUENCE, and spilled ranges, allowing you to easily sort, index, and manage dynamic worksheet values without compatibility errors.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open the worksheet containing your dynamic data array.
- 2. Apply the sorting formula: Select a blank destination cell and input =SORTBY(SEQUENCE(COUNT(J3#)),RANK(J3#,J3#)).
- 3. View the spilled results instantly: Press Enter to let WPS Spreadsheet automatically calculate and spill the sorted row numbers dynamically down the column.

Frequently Asked Questions
What does the hashtag (#) symbol mean in the formula?
The hashtag (#) is the spilled range operator. It is used to reference the entire dynamic array that spills from an anchor cell (such as J3), rather than just referencing a single cell.
Why am I getting a #NAME? error when using this formula?
The #NAME? error typically occurs when the version of your spreadsheet software does not support dynamic array functions like SORTBY or SEQUENCE. Updating to a newer version or switching to WPS Office will resolve this issue.
How does the RANK function handle duplicate values?
The RANK function assigns the exact same numerical rank to identical values. When nested inside the SORTBY formula, it ensures that duplicates are grouped together sequentially based on their ranked position.
Can I sort the row numbers from smallest to largest instead?
Yes, you can modify the sort order by adding a sort_order argument to the SORTBY function. Adding a 1 at the end of the SORTBY arguments will sort the sequence in ascending order, while a -1 sorts it in descending order.




