Dynamic arrays function
SORT function in Google Sheets and Excel
SORT returns a range sorted by one of its columns, ascending or descending, as a list that spills and updates by itself.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
SORT(array, [sort_index], [sort_order], [by_col])Arguments in [brackets] are optional. Google Sheets writes it SORT(range, sort_column, is_ascending, [sort_column2], [is_ascending2]).
Example
=SORT(C2:C9,1,-1) reads: Sort the July sales in C2:C9 by their first (and only) column, largest first.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Rep | Region | Jul | Aug | Sep | Target | Jul sorted | |
| 2 | Amara Osei | North | $12,400 | $13,100 | $11,800 | $36,000 | $15,200 | |
| 3 | Ben Fischer | South | $9,800 | $10,250 | $12,100 | $30,000 | $14,500 | |
| 4 | Lina Chen | East | $15,200 | $14,800 | $16,900 | $45,000 | $13,300 | |
| 5 | Diego Alvarez | West | $8,700 | $9,100 | $8,400 | $28,000 | $12,400 | |
| 6 | Eva Novak | North | $11,200 | $12,600 | $13,900 | $36,000 | $11,200 | |
| 7 | Farid Haddad | South | $13,300 | $12,900 | $14,100 | $39,000 | $10,100 | |
| 8 | Grace Kim | East | $10,100 | $9,600 | $10,800 | $33,000 | $9,800 | |
| 9 | Hugo Martin | West | $14,500 | $15,800 | $15,100 | $42,000 | $8,700 |
H2 shows $15,200, the best July, and the list runs down to $8,700 in H9.
How the spreadsheet calculates it
Sorts C2:C9 by column 1, largest/Z first, and spills the result.
- 1. SORT: Sorts
C2:C9by column1, largest/Z first, and spills the result.array=`C2:C9`: what to sortcolumn=`1`: which column of it to sort byorder=`-1`: `1` ascending, `-1` descending (Google Sheets
More SORT examples
=SORT(A2:C9,3,-1)The reps with region and July sales, best July first.=SORT(UNIQUE(B2:B9))Each region once, A to Z.=SORT(A2:F9,{2,3},{1,-1})By region, then by July sales from high to low.=TAKE(SORT(A2:C9,3,-1),3)The top three reps by July sales.
Paste any of these into the formula explainer to see it step by step.
Tips
- Sort the whole table and choose the column with sort_index, so rows stay together.
- Leave empty space below (or beside, with by_col) for the spill.
- In shared files with Google Sheets users, write the direction for the app the file lives in: -1 in Excel, FALSE in Sheets.
What SORT is used for
Leaderboards and top-performer lists, sorted dropdown sources, reports that stay in order as new rows arrive, and sorted lists of unique values for summaries.
Arguments
| Argument | Required | What it is |
|---|---|---|
| array | Yes | The range to sort, one column or several. |
| sort_index | No | Which column of array to sort by: 1 is the first (the default). |
| sort_order | No | 1 ascending (the default), -1 descending. |
| by_col | No | FALSE (the default) sorts rows; TRUE sorts columns, for data laid out across. |
Common mistakes
Using -1 in Google Sheets: it wants FALSE for descending.
Sorting one column of a table on its own: the names no longer line up with their numbers. Sort the whole table and pick the column with sort_index.
Typing in the cells the sorted list needs: SORT spills, and anything in the way gives #SPILL!.
In Google Sheets
Google Sheets has SORT, but its arguments are written differently: SORT(range, sort_column, is_ascending, [sort_column2], [is_ascending2]). The direction is TRUE (ascending) or FALSE (descending) instead of 1 and -1, and you can add more column and direction pairs to sort by several columns. Google's syntax line has no by_col argument.
Errors you may see with SORT
Questions
How do I sort by two columns?
In Excel, give sort_index and sort_order as arrays: SORT(A2:C9,{2,3},{1,-1}) sorts by region A to Z, then July sales largest first within each region. In Google Sheets, add a second column and direction pair instead.
What's the difference between SORT and SORTBY?
SORT sorts by a column inside the range; SORTBY sorts by another range, which can be outside it or not shown at all. Google Sheets has SORT but not SORTBY.
How do I sort a list without duplicates?
Combine with UNIQUE: SORT(UNIQUE(B2:B9)) gives each region once, A to Z. See the UNIQUE and SORT guide.
Does SORT change my original data?
No. It returns a sorted copy where you type the formula; the original stays as it is, and the copy updates when the original changes.
Sources
Official documentation the facts on this page were checked against.