SORT returns your data in a new order without touching the original. Because the result is a formula, it re-sorts itself whenever the source changes, which the Sort button on the Data tab never does.
The arguments
- array is the block to sort. Every column in it comes back, in the same row order as the sort.
- sort_index says which column of that block to sort by. It counts inside the block: for
A2:C7, 3 means the third column, C. If you leave it out, SORT uses the first column. - sort_order is
1 for A to Z and smallest first, or -1 for the reverse. - by_col is rarely needed. Set it to
TRUE when your data runs across a row, such as months in B1:G1, and you want to reorder the columns.
Sorting by several columns
Give sort_index and sort_order as array constants. =SORT(A2:C7,{2,3},{1,-1}) sorts by the second column A to Z and, inside each group, by the third column largest first. The two arrays must be the same length.
Sorting a calculated result
SORT accepts any array, so you can sort the output of another dynamic array function. =SORT(FILTER(A2:C7,C2:C7>200),3,-1) keeps the rows over 200 and then ranks them. =SORT(UNIQUE(B2:B7)) gives an alphabetical list of the categories.
SORT or SORTBY
SORT picks a column inside the array you are returning. If you want to sort by something that isn't part of the result, such as a column you don't want to show, or a calculated value like text length, use SORTBY instead.
What SORT does and doesn't do
Numbers sort before text, and text sorts alphabetically without regard to case. SORT moves whole rows together, so a name never loses its figure. It returns values, so number formats and fills from the source don't follow the result: format the spill range yourself.
The result is a spill range. If the cells it needs aren't empty you get #SPILL!. See FILTER for how spills work and how to read them with the # operator, as in =SUM(E2#).
If you only want to change the source order once, use the Sort button instead. SORT is for reports and summaries that must stay in order as the data changes.