Lookup & reference function

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])
ArgumentWhat it means
arrayRequiredThe range or array to sort.
sort_indexOptionalWhich column (or row) to sort by, counted inside array. Default 1. Use an array such as {2,3} for several levels.
sort_orderOptional1 ascending (default) or -1 descending. Use an array such as {1,-1} to match several sort columns.
by_colOptionalFALSE (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

D2fx=SORT(A2:B6, 2, -1)
ABCDE
1StudentScore
2Raj88Omar91
3Lena78Raj88
4Sofia84Sofia84
5Omar91Lena78
6Pia65Pia65

The second column of A2:B6 (Score) is sorted in descending order; each name stays with its score.

2Alphabetical list of names

D2fx=SORT(A2:A6)
ABCD
1StudentScore
2Raj88Lena
3Lena78Omar
4Sofia84Pia
5Omar91Raj
6Pia65Sofia

With only one argument SORT orders the list A to Z.

3Two sort levels

G2fx=SORT(A2:E8, {2,5}, {1,-1})
ABCDEFGHIJK
1RepRegionProductUnitsRevenue
2AnaNorthLaptop43600AnaEastLaptop21800
3BenSouthMonitor101490BenEastMouse30360
4ChloeNorthMonitor6894AnaNorthLaptop43600
5AnaEastLaptop21800ChloeNorthMonitor6894
6DevSouthLaptop54500ChloeNorthMouse12144
7BenEastMouse30360DevSouthLaptop54500
8ChloeNorthMouse12144BenSouthMonitor101490

First by Region (column 2) A-Z, then by Revenue (column 5) largest first inside each region.

4Top 3 with TAKE

D2fx=TAKE(SORT(A2:B6, 2, -1), 3)
ABCDE
1StudentScore
2Raj88Omar91
3Lena78Raj88
4Sofia84Sofia84
5Omar91
6Pia65

TAKE keeps the first three rows of the sorted list - a live top-3 table.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 19 KB

Common errors and how to fix them

ErrorWhy it happensFix
#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_col TRUE: =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.

LanguageFunction name
DanishSORTER
DutchSORTEREN
FinnishLAJITTELE
FrenchTRIER
GermanSORTIEREN
HungarianSORBA.RENDEZ
ItalianDATI.ORDINA
Norwegian (Bokmål)SORTER
PolishSORTUJ
Portuguese (Brazil)CLASSIFICAR
Portuguese (Portugal)ORDENAR
RussianСОРТ
SpanishORDENAR
SwedishSORTERA
TurkishSIRALA

Recipes that use SORT