Excel Lessons

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.

Published . 5 min read.

By Ali, Founder, Excel Lessons

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 TitleGenreSold
2 Salt RoadFiction84
3 Green WallsGarden57
4 Night TrainFiction132
5 Clay and FireCraft45
6 Small PlotsGarden98
7 KnotsCraft71
8 Paper MoonFiction66

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 FireCraft45
Green WallsGarden57
KnotsCraft71
Night TrainFiction132
Paper MoonFiction66
Salt RoadFiction84
Small PlotsGarden98

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 TrainFiction132
Small PlotsGarden98
Salt RoadFiction84
KnotsCraft71
Paper MoonFiction66
Green WallsGarden57
Clay and FireCraft45

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:

KnotsCraft71
Clay and FireCraft45
Night TrainFiction132
Salt RoadFiction84
Paper MoonFiction66
Small PlotsGarden98
Green WallsGarden57

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 buttonSORT function
Changes the dataYesNo, it makes a copy
Updates when a number changesNoYes
Works in Excel 2019 and olderYesNo

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.

Related articles