The SORT function
Sorts the rows of a range by one of its columns and spills the sorted copy into the cells below. The original data stays as it is.
Syntax
SORT(array, [sort_index], [sort_order], [by_col])- array
- The range to sort.
- sort_index (optional)
- Which column of the range to sort by, counted from 1. Left out, the first column.
- sort_order (optional)
- 1 or left out for smallest to largest (A to Z), -1 for largest to smallest.
- by_col (optional)
- TRUE to sort the columns of the range instead of its rows.
Examples
D1=SORT(A2:B5)
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Sales | Ava | 275 | |
| 2 | Maya | 320 | Ben | 450 | |
| 3 | Ben | 450 | Maya | 320 | |
| 4 | Zoe | 180 | Zoe | 180 | |
| 5 | Ava | 275 |
D1
=SORT(1A2:B5,22,3-1)| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Sales | Ben | 450 | |
| 2 | Maya | 320 | Maya | 320 | |
| 3 | Ben | 450 | Ava | 275 | |
| 4 | Zoe | 180 | Zoe | 180 | |
| 5 | Ava | 275 |
In plain words: Sort 1the names and sales in A2:B5 by 2the second column, 3largest first.
D1=SORT(B2:B5)
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Name | Sales | 180 | |
| 2 | Maya | 320 | 275 | |
| 3 | Ben | 450 | 320 | |
| 4 | Zoe | 180 | 450 | |
| 5 | Ava | 275 |
Practice SORT
Read the guide
Questions
Why does SORT return
The sorted result needs empty cells to spill into, and something is in the way. Clear the cells below and to the right of the formula.
Does SORT work the same way in Google Sheets?
Google Sheets has SORT too, but its arguments differ. You give the column to sort by and TRUE or FALSE for ascending, as in =SORT(A2:B5,2,FALSE), and you can add more column and order pairs.