Excel function

SORTfunction

Sorts a range by a chosen column and spills the result into several cells.

Excel 2021+
=SORT(A2:D9, 4, -1)
A
B
C
D
E
F
G
H
I
1
2
3
4
5
6
7
8
9

Drag the corner dots to change array. Click the numbers on the top to change sort_index. Click a cell in the table to sort by that column. Rows with equal values keep their original order. Try breaking it on purpose to see the errors.

Result

{"Seoul","Milk",40,96000;"Busan","Coffee",15,67500;"Daegu","Bread",18,57600;"Seoul","Apple",30,45000;"Busan","Apple",25,37500;"Daegu","Apple",20,30000;"Busan","Milk",12,28800;"Seoul","Bread",8,25600}

array
A2:D9Drag the corner dots on the table

The range to sort.

sort_index
4array has 4 columns

Which column of the array to sort by. Omitted means 1.

sort_order

1 sorts smallest first (ascending), -1 largest first (descending). Omitted means 1.

What is the SORT function?

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

SORT returns a sorted copy of a range. Unlike the Sort button, it leaves the original table alone and builds the sorted version elsewhere. When the source values change, the order updates right away.

The result is an array the same size as the original, spilling from the formula cell. Per Microsoft documentation, it is available in Excel 2021 and later and Microsoft 365.

Arguments

array
The range to sort.
sort_index
Optional. Which column of the array (or row, with by_col) to sort by. Omitted means 1.
sort_order
Optional. 1 for ascending (smallest first), -1 for descending (largest first). Omitted means 1.
by_col
Optional. FALSE (default) sorts rows top to bottom; TRUE sorts columns left to right.

SORT examples

  1. Example 1. First column, ascending

    =SORT(A2:D9)

    Rows sorted by branch name.

  2. Example 2. Largest sales first

    =SORT(A2:D9, 4, -1)

    Sorted by the 4th column (Sales), largest first.

  3. Example 3. Sort one column

    =SORT(B2:B9)

    A sorted list of product names.

  4. Example 4. Sorted, no duplicates

    =SORT(UNIQUE(B2:B9))

    Each product name once, sorted.

Common mistakes

FAQ

What order do tied rows get?
The calculation on this page keeps their original order. To make the order certain, give SORTBY a second key.
How do I sort by two keys?
You can pass arrays for the column and order, like =SORT(A2:D9, {1,4}, {1,-1}). If the key is outside the table, SORTBY is easier.
How do I sort the original table?
SORT makes a copy. To change the table itself, use Sort on the Data tab.