What SORT does
SORT returns a copy of a range sorted by one of its columns, and it sorts again by itself whenever a value changes. =SORT(A2:B6,2,-1) lists a support team by the tickets each agent closed, most first, while the original list keeps its order. Whole rows move together, so every name keeps its own figure.
Data > Sort rearranges the cells themselves, and only when you run it. SORT leaves them where they are and shows a sorted copy wherever you write the formula, which suits a leaderboard or a report that has to stay in order as the figures come in.
The copy spills into the cells below and to the right of the formula, as many as it needs. A value already typed in that space stops it, and the formula shows #SPILL!.
Syntax
arrayRequired- The range to sort, such as
A2:B6. Start it below the headings, or they get sorted in with the data. sort_indexOptional- Which column of
arrayto sort by, counting from its left edge:2is the second column of the range, wherever it sits on the sheet. Left out, SORT uses the first column. sort_orderOptional1for smallest first or A to Z, which is the default, and-1for largest first or Z to A.by_colOptional- Leave it out to sort the rows, which is what a list needs.
TRUEsorts the columns of a range laid out across the sheet.
Example: a leaderboard, largest first
A help desk keeps each agent’s closed tickets for the week in column B. The formula in A9 sorts the whole list by that column, most tickets first, under headings typed in row 8.
Change Priya’s 38 to 60 and she moves to the top of the copy straight away. Leave out the -1 and the list runs the other way, fewest tickets first.
Example: tasks in order of their due date
A team’s task list is in the order tasks were added. The formula in A9 sorts it by the due dates in the third column, earliest first.
The cells C9:C13 have a date format, so the due dates in the sorted copy show as dates. If yours show as numbers such as 46367, format the cells where they land as dates.
Sort by more than one column with SORTBY
SORT sorts by one column. SORTBY takes a range to sort by and an order for each level, so =SORTBY(A2:C6,B2:B6,1,C2:C6,1) on the task list above groups the tasks by owner, A to Z, and puts each owner’s tasks in order of their due date. Dana’s tasks come first, with Desk moves, due Dec 18, before Supplier review.
SORTBY can also sort by a column it doesn’t return: =SORTBY(A2:A6,C2:C6,-1) lists only the task names, latest due date first.
Sort a filtered or unique list
SORT takes the result of another formula as easily as a range. =SORT(UNIQUE(B2:B50)) lists each owner once, from A to Z, and =SORT(FILTER(A2:C50,B2:B50="Dana"),3) lists Dana’s tasks in order of their due dates.
Common mistakes
=SORT(A1:B6,2,-1)includes the heading row, and “Closed” is sorted in with the numbers. Start the range on the first row of data.=SORT(B2:B6,1,-1)sorts the ticket counts on their own, so they lose their names. Give SORT the whole rows, A2:B6.- sort_index counts from the left edge of the range, not of the sheet. In
=SORT(B2:D9,2)the 2 means column C. - SORT isn’t in Excel 2019 or earlier, where the formula shows
#NAME?. There, copy the list and use Data > Sort on the copy, and sort it again when the figures change.
Frequently asked questions
How do I sort in descending order with the SORT function?
Give -1 as the third argument: =SORT(A2:B6,2,-1) sorts by the second column, largest first. Text sorts Z to A the same way.
How do I sort by multiple columns with a formula?
Use SORTBY, which takes a range and an order for each level: =SORTBY(A2:C20,B2:B20,1,C2:C20,-1) sorts by column B, A to Z, and within each value of B by column C, largest first.
What is the difference between SORT and SORTBY?
SORT sorts by one column of the range it returns, picked by its number. SORTBY sorts by ranges you name, as many levels as you need, and those ranges don’t have to be part of the result.
Does the SORT function change my data?
No. The original range stays as it is, and SORT shows a sorted copy where you write the formula. To reorder the cells themselves, use Data > Sort.
How do I sort a list alphabetically with a formula?
Give SORT the list and nothing else: =SORT(A2:A20) returns the names from A to Z. For each name once, use =SORT(UNIQUE(A2:A20)).
Which versions of Excel have SORT?
Microsoft 365, Excel for the web, and Excel 2021 or later. Excel 2019 and earlier don’t have it.