The Excel SORT function returns a sorted copy of a range that spills onto the worksheet — the original data never moves, and the result re-sorts itself automatically whenever the source changes. One formula replaces the manual Data › Sort routine forever. Pair it with FILTER and UNIQUE and you have a live, self-maintaining report.
3 is the column to sort by (counted inside the range), and -1 means descending. Omit both and SORT sorts by the first column, ascending.
Syntax
| Argument | Description | |
|---|---|---|
array | Required | The range or array to sort. Do not include the header row. |
sort_index | Optional | Which column (or row, with by_col) to sort by, counted within the array. Default is 1. |
sort_order | Optional | 1 = ascending (default) · -1 = descending. Nothing else is accepted. |
by_col | Optional | FALSE (default) sorts rows top-to-bottom. TRUE sorts columns left-to-right — for horizontal data. |
Available in: Excel for Microsoft 365, Excel 2021+, and Excel for the web. Older versions show #NAME?. The result is a dynamic array: it spills into the cells below and to the right of the formula.
Sort a table by one column
The product table sits in A2:C7 (headers in row 1). One formula in E2 returns the whole table sorted by Units, biggest sellers first — the headers in E1:G1 are typed normally:
| A | B | C | E | F | G | ||
|---|---|---|---|---|---|---|---|
| 1 | Product | Category | Units | Product | Category | Units | |
| 2 | Laptop Stand | Accessories | 1,840 | Ring Light | Video | 3,120 | |
| 3 | USB-C Hub | Accessories | 2,650 | USB-C Hub | Accessories | 2,650 | |
| 4 | Monitor 27in | Displays | 980 | Webcam Pro | Video | 2,210 | |
| 5 | Ring Light | Video | 3,120 | Laptop Stand | Accessories | 1,840 | |
| 6 | Desk Mat XL | Accessories | 1,410 | Desk Mat XL | Accessories | 1,410 | |
| 7 | Webcam Pro | Video | 2,210 | Monitor 27in | Displays | 980 |
Type a new number in column C and the spilled copy reorders instantly. To refer to the whole result elsewhere, use the spill operator: E2#.
For a single column, the defaults are all you need:
Try it: interactive SORT demo
Sort the product table live: pick a column and a direction, and watch the spilled result reorder.
Multi-level sorts and dynamic-array combos
Pass array constants to sort_index and sort_order for a multi-level sort — here Category A→Z, then Units largest-first within each category:
SORT shines as the outer layer of other dynamic array functions:
For horizontal data — months running across the top — set by_col to TRUE:
Need to sort by a column you don’t want in the output? That’s exactly what SORTBY is for.
Errors & common pitfalls
#SPILL! — the landing zone isn’t empty. SORT needs as many blank cells as the array it returns. Anything in the way — even a stray space — blocks the spill. Click the error’s warning icon to highlight the obstruction, then clear it.
#VALUE! — bad sort_index or sort_order. sort_index must point at a column that exists inside the array, and sort_order only accepts 1 or -1 (not 0, not TRUE/FALSE).
#NAME? — older Excel. SORT exists only in Excel 2021+ and Microsoft 365. In Excel 2019 and earlier the name isn’t recognized — there is no direct equivalent short of helper columns or VBA.
Pitfall: headers inside the array. Include row 1 in array and your header line gets sorted into the data. Start the range at the first data row and type headers above the spill yourself.
Pitfall: you can’t edit a spilled result. The sorted copy is read-only output — typing in it triggers #SPILL! on the source formula. Edit the original data instead; the spill follows along.
Practice workbook
Frequently asked questions
What's the difference between SORT and SORTBY?
How do I sort by multiple columns with SORT?
=SORT(A2:C20, {2,3}, {1,-1}) sorts by column 2 ascending, then column 3 descending. For unlimited keys with cleaner syntax, use SORTBY.Does SORT change my original data?
Why does SORT return #NAME? on my computer?
How do I sort Z to A (descending)?
=SORT(A2:A20, 1, -1). The sort_order argument accepts only 1 (ascending) or -1 (descending).Master functions like this in one day
This page covers one function. Our Excel Formulas and Functions class covers the 30 that matter most — live, hands-on, taught by professionals in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class