SORT in Excel: a sorted list that updates by itself
SORT gives a sorted copy of a range that updates by itself. Sort by any column, largest first, or by two columns, and how it differs from the Sort button.
The SORT function in Excel returns a sorted copy of a range. The original data does not move. When a number in the data changes, the sorted copy changes by itself.
SORT is in Excel 2021, Excel 2024, Microsoft 365 and Excel for the web. Excel 2019 and older do not have it.
A small bookshop keeps a list of titles, the genre, and the copies sold this month. The owner types in new sales every week. She wants a best-seller list next to it that is always in order.
| Row | A | B | C |
|---|---|---|---|
| 1 | Title | Genre | Sold |
| 2 | Salt Road | Fiction | 84 |
| 3 | Green Walls | Garden | 57 |
| 4 | Night Train | Fiction | 132 |
| 5 | Clay and Fire | Craft | 45 |
| 6 | Small Plots | Garden | 98 |
| 7 | Knots | Craft | 71 |
| 8 | Paper Moon | Fiction | 66 |
The shape is =SORT(range, sort column, order). Only the range is
needed. Type each formula in E2, and keep the cells below and to the right empty.
The simplest SORT
=SORT(A2:C8) sorts by the first column, A to Z. It fills E2 to
G8:
| Clay and Fire | Craft | 45 |
| Green Walls | Garden | 57 |
| Knots | Craft | 71 |
| Night Train | Fiction | 132 |
| Paper Moon | Fiction | 66 |
| Salt Road | Fiction | 84 |
| Small Plots | Garden | 98 |
Each row stays together. Knots is still next to Craft and 71. That is why you give SORT the whole table, not one column.
Sort by any column, largest first
The second part picks the column to sort by. It counts from the left of the range, not from column A of the sheet. The third part is 1 for smallest first, or -1 for largest first.
=SORT(A2:C8,3,-1) sorts by Sold, largest first:
| Night Train | Fiction | 132 |
| Small Plots | Garden | 98 |
| Salt Road | Fiction | 84 |
| Knots | Craft | 71 |
| Paper Moon | Fiction | 66 |
| Green Walls | Garden | 57 |
| Clay and Fire | Craft | 45 |
Now change C8 from 66 to 150. Paper Moon moves to the top of the list. You did not touch the formula.
To get one value out of the list, put INDEX around it.
=INDEX(SORT(A2:C8,3,-1),2,1) gives Small Plots, the second best
seller. The 2,1 means row 2, column 1 of the sorted list.
Sort by two columns
The owner wants the list by genre, and the best seller first inside each genre. Give SORT two columns and two orders, each in curly brackets.
=SORT(A2:C8,{2,3},{1,-1}) sorts by Genre A
to Z, then by Sold largest first:
| Knots | Craft | 71 |
| Clay and Fire | Craft | 45 |
| Night Train | Fiction | 132 |
| Salt Road | Fiction | 84 |
| Paper Moon | Fiction | 66 |
| Small Plots | Garden | 98 |
| Green Walls | Garden | 57 |
The first pair, 2 and 1, is the main sort. The second pair, 3 and -1, only decides the order inside each genre.
Sort by a column you do not show
Sometimes you want only the titles, in order of sales. SORT cannot do that, because it sorts by a column inside the range. SORTBY can. It takes the range to return, then the column to sort by.
=SORTBY(A2:A8,C2:C8,-1) fills E2 to E8:
| Night Train |
| Small Plots |
| Salt Road |
| Knots |
| Paper Moon |
| Green Walls |
| Clay and Fire |
SORTBY is in the same versions of Excel as SORT.
SORT or the Sort button?
The Sort button is on the Data tab. It moves the rows of the table itself. SORT leaves the table alone and builds a copy somewhere else.
| Sort button | SORT function | |
|---|---|---|
| Changes the data | Yes | No, it makes a copy |
| Updates when a number changes | No | Yes |
| Works in Excel 2019 and older | Yes | No |
Use the Sort button to put a list in order once. Also use it when the file goes to somebody with an older Excel. Use SORT when the data keeps changing and the order must stay right. A weekly report is the usual case.
One more difference. Every cell of a SORT result belongs to the formula in E2. Type in one of
them and the formula shows #SPILL!. To change a number, change it
in the data.
What goes wrong
The header is in the range. =SORT(A1:C8,3,-1)
sorts the word Sold with the numbers. Excel puts text after numbers. So largest first, the
header lands at the top and looks fine. Change -1 to 1 and it drops to the bottom. Start the
range at row 2.
A number saved as text. Say C5 came from a till system as the text 45. Sort smallest first, and Clay and Fire goes to the bottom, not the top. Text always sorts after numbers. The numbers stored as text article shows how to find and fix it.
Something is in the way. The result needs 7 empty rows. One label in E5 turns
the whole answer into #SPILL!.
New rows are outside the range. A book added in row 9 is not in A2:C8. Make the data an Excel table with Ctrl+T, and use the table's name in the formula. Then new rows are included.
SORT with other functions
SORT works well around other functions that return lists.
=SORT(UNIQUE(B2:B8)) gives each genre once, A to Z: Craft,
Fiction, Garden.
=SORT(FILTER(A2:C8,B2:B8="Fiction"),3,-1) gives only the fiction
titles, best seller first: Night Train, Salt Road, Paper Moon. The
FILTER function article has more of these.
You can practise SORT in the lessons below. Each lesson is a real sheet you type into, and each answer is checked when you press Enter.