All Excel functions

SORT in Excel: how to use it

SORT gives a sorted copy of your data that updates itself when the source changes. Available in Excel 2021 and 365.

Try the first exercises for freeIn the lesson The SORT function

What does SORT do?

SORT shows a sorted copy of your data somewhere else. Your original list stays as it is, and the copy updates itself when something changes.

With the second argument you choose which column to sort by, and with the third in which direction: 1 from low to high, -1 from high to low. SORTBY sorts by a column that you don't show yourself. Both work in Excel 2021 and 365.

When do you use SORT?

  • A ranking that updates itself, from high to low: =SORT(A2:B20,2,-1).
  • An alphabetical list of names: =SORT(A2:A50).
  • Only the names, sorted by their score: =SORTBY(A2:A20,B2:B20,-1).
  • A list without duplicates, in alphabetical order: =SORT(UNIQUE(A2:A100)).

Syntax

The syntax is the fixed pattern of a function. The words in the brackets are placeholders: that's where you fill something in yourself, such as a cell, a number or a piece of text. Everything else you type exactly as it is.

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

A sorted copy of your data that updates itself.

Filled in: =SORT(C2:C6,1,-1)

This is how to read the formula, part by part:

PartWhat it meansIn the example
=Every formula starts with an equals sign. Without =, Excel treats what you type as ordinary text.=
SORTThe name of the function: that's how Excel knows what to do. You can type it in lower case, Excel puts it in capitals itself.SORT
( )Straight after the name come the brackets. Inside them is what the function needs to work: the arguments.( )
arrayWhat you want to show sorted: one column or a whole table.C2:C6
[sort_index]Optional: which column of your range to sort by. Count from 1.1
[sort_order]Optional: 1 from low to high, -1 from high to low.-1
,A comma separates the arguments from each other.,
[ ]Anything in square brackets can be left out. You never type the square brackets themselves.

SORT step by step

E1 contains =SORT(C2:C6,1,-1). With -1 the highest value comes first. Change the numbers or the formula and see what happens.

E1
A
B
C
D
E
F
G
H
1
Region
Product
Revenue
1200
2
Leeds
Laptop
1200
980
3
York
Monitor
340
410
4
Leeds
Monitor
410
340
5
Bristol
Laptop
980
75
6
York
Mouse
75
7
8
9
10
Ready

This is how to build the formula yourself:

  1. Click E1, with empty cells below it, and type SORT with a bracket.=SORT(
  2. Select what you want to see sorted, the revenue in C2:C6, and type a comma.=SORT(C2:C6,
  3. Type which column of your range to sort by: there's only one, so 1. Type a comma.=SORT(C2:C6,1,
  4. Type -1 for high to low, close the bracket and press Enter.=SORT(C2:C6,1,-1)

More examples

Sorting the whole table

E1 contains =SORT(A2:C6,3,-1). Sort A2:C6 by the third column, the revenue: the whole row moves with it, and Leeds with 1200 is at the top.

E1
A
B
C
D
E
F
G
H
1
Region
Product
Revenue
Leeds
Laptop
1200
2
Leeds
Laptop
1200
Bristol
Laptop
980
3
York
Monitor
340
Leeds
Monitor
410
4
Leeds
Monitor
410
York
Monitor
340
5
Bristol
Laptop
980
York
Mouse
75
6
York
Mouse
75
7
8
9
10
Ready

Sorting by another column

E1 contains =SORTBY(B2:B6,C2:C6,-1). Only the products, but in the order of the revenue next to them.

E1
A
B
C
D
E
F
G
H
1
Region
Product
Revenue
Laptop
2
Leeds
Laptop
1200
Laptop
3
York
Monitor
340
Monitor
4
Leeds
Monitor
410
Monitor
5
Bristol
Laptop
980
Mouse
6
York
Mouse
75
7
8
9
10
Ready

In alphabetical order

E1 contains =SORT(A2:A6). Without other arguments, SORT sorts from A to Z.

E1
A
B
C
D
E
F
G
H
1
Region
Product
Revenue
Bristol
2
Leeds
Laptop
1200
Leeds
3
York
Monitor
340
Leeds
4
Leeds
Monitor
410
York
5
Bristol
Laptop
980
York
6
York
Mouse
75
7
8
9
10
Ready

Sorting with a formula or with the button?

The button changes your table itself. The formula leaves the source alone and updates automatically.

Where it often goes wrong

  • You can't edit the result directly.
Want to try it yourself?
Practise this in the lesson The SORT function. The first exercises are free.

Try the first exercises for free

Frequently asked questions

Can I sort by two columns?

Yes, in Excel 365 with SORTBY.

Read next

UNIQUEFILTERSUMPRODUCTCHOOSECOLSLET