Function · Dynamic arrays
Excel SORT function
The Excel SORT function returns a range sorted by one of its columns and spills the rows. The four utility bills, sorted by amount, start with April's $88.10.
Syntax =SORT(array, [sort_index], [sort_order], [by_col])
=SORT(A2:B5,2,1)Arguments
| Name | Required | What to pass |
|---|---|---|
| array | Required | The rows to sort, including the column you sort by. |
| sort_index | Optional | Which column to sort by, counting the first column of array as 1. The default is 1. |
| sort_order | Optional | 1, the default, is ascending. -1 is descending. |
| by_col | Optional | FALSE, the default, sorts rows. TRUE sorts columns left to right. |
Examples
The four utility bills from smallest to largest
=SORT(A2:B5,2,1)Result Apr $88.10, Feb $96.20, Mar $118.45, Jan $143.60
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Month | Bill | Month | Bill | |
| 2 | Jan | 143.60 | Apr | 88.10 | |
| 3 | Feb | 96.20 | Feb | 96.20 | |
| 4 | Mar | 118.45 | Mar | 118.45 | |
| 5 | Apr | 88.10 | Jan | 143.60 |
SORT returns a new list. It does not rearrange the cells you already have. The four utility bills sorted by the amount column, smallest first, are April $88.10, February $96.20, March $118.45, and January $143.60. The months in column A stay where they were. The spill in D2:E5 is the sorted copy.
sort_index 2 is the bill, because the array starts at column A. sort_order 1 is ascending and -1 is descending, so -1 would put January first. Text sorts alphabetically. A header inside the array sorts with the data, which is why this range starts at row 2. Excel 2019 does not have SORT. The Data tab’s Sort command is the one that rewrites the sheet in place.