Dynamic arrays function
Excel SORT function
SORT returns a sorted copy of a range, and it re-sorts by itself when the data changes. Use it for live leaderboards, low-stock lists, or any report where the source should stay in its original order.
=SORT(array, [sort_index], [sort_order])Arguments
array- The range to sort.
sort_index- Optional. Which column of the range to sort by. Default is 1.
sort_order- Optional. 1 for ascending (default), -1 for descending.
SORT examples
Every result below was calculated from this sample sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | |
|---|---|---|---|
| 1 | Product | Bin | On hand |
| 2 | Desk fan | B-04 | 18 |
| 3 | Space heater | B-07 | 6 |
| 4 | Air purifier | A-02 | 11 |
| 5 | Humidifier | A-09 | 3 |
| 6 | Dehumidifier | C-01 | 9 |
Result: spills 5 rows × 1 column
Air purifier Dehumidifier Desk fan Humidifier Space heater Product names in A to Z order, starting with Air purifier.
Result: spills 5 rows × 3 columns
Humidifier A-09 3 Space heater B-07 6 Dehumidifier C-01 9 Air purifier A-02 11 Desk fan B-04 18 The whole table sorted by stock, lowest first. Humidifier tops the list.
Result: spills 5 rows × 3 columns
Desk fan B-04 18 Air purifier A-02 11 Dehumidifier C-01 9 Space heater B-07 6 Humidifier A-09 3 Use -1 to sort descending: the best-stocked item comes first.
Result: 18
Take the first row of a descending sort to get the top value.
How to use SORT
- Click the top-left cell of an empty area.
- Type =SORT( and select the data, without headers.
- Add the column number to sort by, and -1 for largest first.
- Press Enter. The sorted copy spills out.
Common SORT mistakes
Including the header row
The header gets sorted in with the data. Select from row 2 and type the headers above the formula.
Using a column letter for sort_index
sort_index is a number counted from the left of the range, not the sheet column.
Getting #SPILL!
Clear the cells where the sorted result needs to go.
SORT FAQ
How do I sort data automatically in Excel with a formula?
Use =SORT(A2:C20,2,-1). The result re-sorts whenever the source data changes.
How do I sort by multiple columns with SORT?
Pass arrays for both arguments, like =SORT(A2:C20,{2,3},{1,-1}), to sort by column 2 then column 3. Or use SORTBY.
Does the SORT function change my original data?
No. It returns a sorted copy somewhere else. The source stays exactly as it was.
Practice SORT in these lessons
Guides that use SORT
- How to remove duplicates in Excel
- How to count unique values in Excel
- How to return multiple matches in Excel
- #SPILL! error in Excel
Related functions
UNIQUERemoves duplicates, spillsFILTERKeeps matching rows, spillsINDEXValue at a positionLARGEk-th largest
Updated