SORT function
Sorts the contents of a range or array by one or more columns and returns the sorted copy as a spilled list.
Available in Microsoft 365, Excel 2021 and later, Excel for the web, Excel for Mac 2021+
Excel 2021 and laterDifferent in Google Sheets
Syntax
SORT(array, [sort_index], [sort_order], [by_col])| Argument | What it means | |
|---|---|---|
array | Required | The range or array to sort. |
sort_index | Optional | Which column (or row) to sort by, counted inside array. Default 1. Use an array such as {2,3} for several levels. |
sort_order | Optional | 1 ascending (default) or -1 descending. Use an array such as {1,-1} to match several sort columns. |
by_col | Optional | FALSE (default) sorts rows; TRUE sorts columns left to right. |
Returns: A sorted copy of array, the same size as the original, which spills.
How SORT works
SORT gives you a sorted copy of a list without touching the original data. Type =SORT(A2:B6, 2, -1) and a leaderboard ordered by the second column, highest first, appears next to your table. Because it is a formula, it re-sorts itself whenever a number changes - no more clicking the Sort button after every update.
The sort_index is the column number inside the range you are sorting, not the sheet column letter. Sorting is ascending unless you give -1. To sort by more than one column, pass arrays: {2,5} with {1,-1} sorts by column 2 A-Z and then by column 5 largest-first within each group. Numbers sort before text, and blanks go last.
SORT can only sort by columns that are part of the output. To sort by a column you do not want to display, use SORTBY. SORT is often wrapped around FILTER or UNIQUE, and TAKE turns a sorted list into a top-N report.
Examples
1Leaderboard, highest score first
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Student | Score | |||
| 2 | Raj | 88 | Omar | 91 | |
| 3 | Lena | 78 | Raj | 88 | |
| 4 | Sofia | 84 | Sofia | 84 | |
| 5 | Omar | 91 | Lena | 78 | |
| 6 | Pia | 65 | Pia | 65 |
The second column of A2:B6 (Score) is sorted in descending order; each name stays with its score.
2Alphabetical list of names
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | ||
| 2 | Raj | 88 | Lena | |
| 3 | Lena | 78 | Omar | |
| 4 | Sofia | 84 | Pia | |
| 5 | Omar | 91 | Raj | |
| 6 | Pia | 65 | Sofia |
With only one argument SORT orders the list A to Z.
3Two sort levels
| A | B | C | D | E | F | G | H | I | J | K | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Rep | Region | Product | Units | Revenue | ||||||
| 2 | Ana | North | Laptop | 4 | 3600 | Ana | East | Laptop | 2 | 1800 | |
| 3 | Ben | South | Monitor | 10 | 1490 | Ben | East | Mouse | 30 | 360 | |
| 4 | Chloe | North | Monitor | 6 | 894 | Ana | North | Laptop | 4 | 3600 | |
| 5 | Ana | East | Laptop | 2 | 1800 | Chloe | North | Monitor | 6 | 894 | |
| 6 | Dev | South | Laptop | 5 | 4500 | Chloe | North | Mouse | 12 | 144 | |
| 7 | Ben | East | Mouse | 30 | 360 | Dev | South | Laptop | 5 | 4500 | |
| 8 | Chloe | North | Mouse | 12 | 144 | Ben | South | Monitor | 10 | 1490 |
First by Region (column 2) A-Z, then by Revenue (column 5) largest first inside each region.
4Top 3 with TAKE
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Student | Score | |||
| 2 | Raj | 88 | Omar | 91 | |
| 3 | Lena | 78 | Raj | 88 | |
| 4 | Sofia | 84 | Sofia | 84 | |
| 5 | Omar | 91 | |||
| 6 | Pia | 65 |
TAKE keeps the first three rows of the sorted list - a live top-3 table.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#VALUE! | sort_index is larger than the number of columns in array, or sort_order is not 1 or -1. | Count columns inside the range, starting from 1. |
#SPILL! | The output area is not empty or the formula is inside an Excel table. | Clear the cells or move the formula. |
Tips
- Sort a horizontal list with
by_colTRUE:=SORT(B1:E2, 2, -1, TRUE)orders the quarters by the values in row 2. - Sorting is not case-sensitive and keeps rows together, so you never mix up names and scores.
- Combine with FILTER:
=SORT(FILTER(A2:E8, B2:B8="North"), 5, -1).
Questions
Does SORT change my original data?
No. It creates a sorted copy in another place; the source range stays exactly as it was.
How do I sort by a column that I don't want to show?
Use SORTBY, which takes the sort column as a separate range: =SORTBY(A2:A8, E2:E8, -1).
Google Sheets
Exists with a different syntax: SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2], ...), using TRUE/FALSE instead of sort_order 1/-1 and with no by_col argument.
SORT in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | SORTER |
| Dutch | SORTEREN |
| Finnish | LAJITTELE |
| French | TRIER |
| German | SORTIEREN |
| Hungarian | SORBA.RENDEZ |
| Italian | DATI.ORDINA |
| Norwegian (Bokmål) | SORTER |
| Polish | SORTUJ |
| Portuguese (Brazil) | CLASSIFICAR |
| Portuguese (Portugal) | ORDENAR |
| Russian | СОРТ |
| Spanish | ORDENAR |
| Swedish | SORTERA |
| Turkish | SIRALA |
Recipes that use SORT
- How to create a dependent drop-down list in Excel
- How to create a drop-down list in Excel
- How to list the top 5 values with names in Excel
- How to rank numbers with ties in Excel
- How to remove duplicates in Excel
- How to sum by category in Excel