fxExcelReps
← All functions ⇣ Dynamic arrays · Intermediate

SORT A sorted copy of a range that updates itself.

How to use SORT in Excel

SORT returns a sorted copy of a range, and SORTBY sorts one range by the values of another. The original data stays where it is and the sorted list updates itself.

Syntax

=SORT(array, [sort_index], [sort_order])

arrayThe range to sort, e.g. A2:B500.
[sort_index]Optional. Which column to sort by: 1, 2, 3… Default 1.
[sort_order]Optional. 1 ascending (A→Z, smallest first), -1 descending.

Examples

=SORT(A2:B500, 2, -1)The table sorted by the second column, largest first.
=SORT(A2:A500)A list from A to Z.
=SORTBY(A2:A500, B2:B500, -1)Only the names, sorted by the scores next to them.
=TAKE(SORT(A2:B500, 2, -1), 5)The top 5 rows (Microsoft 365).

Rankings that update themselves

A sorted copy next to the data is perfect for dashboards: the top clients, the largest exposures, the latest payments.

=SORT(A2:C500, 3, -1)The table sorted by the third column, largest first.
=TAKE(SORT(A2:C500, 3, -1), 10)Only the top 10 rows (Microsoft 365).

Sort by two columns

SORTBY takes pairs of a column and an order, so you can sort by region and then by amount.

=SORTBY(A2:C500, A2:A500, 1, C2:C500, -1)Region A to Z, then the largest amount first within each region.
=SORT(UNIQUE(B2:B500))Unique names, sorted.

Common mistakes

#SPILL! error
Cells in the way of the result. Clear them.
#VALUE! error
sort_index is larger than the number of columns, or sort_order isn't 1 or -1.
The original data didn't change
That's by design: SORT returns a copy. To sort the data itself, use Data → Sort.

Frequently asked questions

What's the difference between SORT and SORTBY?

SORT sorts by a column number inside the range. SORTBY sorts by any range of the same height, even one you don't return, and takes several sort keys.

Does SORT change my data?

No. It returns a sorted copy. Use Data → Sort to sort the data itself.

How do I sort from largest to smallest?

Use -1 as the sort order: =SORT(A2:B500, 2, -1).

How do I get the top 5 with names in older Excel?

Use LARGE for the values and INDEX/MATCH or XLOOKUP for the names.

Available in: Microsoft 365, Excel 2021 and newer, Excel for the web, Google Sheets

Related functions

UNIQUEFILTERLARGEINDEX

How-to guides that use it

↑ Practise SORT in the sheet above