Spreadsheet Practice

SORT function

SORT returns a sorted copy of a range, ordered by any column you choose, smallest to largest or the reverse. The original data stays where it is, and the sorted copy reorders itself whenever the numbers change, which makes it the backbone of leaderboards and ranked reports.

Available in
Excel 2021, 2024 and Microsoft 365
Category
Dynamic array functions
Returns
A sorted copy of array, the same size as the original. It spills.
Google Sheets
Google Sheets has SORT, but its arguments differ: you give a column number and TRUE or FALSE for ascending.

Syntax

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

ArgumentRequired?What it is
arrayRequiredThe range to sort. Leave out the header row.
sort_indexOptionalWhich column to sort by, counting from the left edge of array. The default is 1.
sort_orderOptional1 sorts ascending (the default). -1 sorts descending.
by_colOptionalTRUE sorts columns left to right instead of rows. The default is FALSE.

Examples

Each result below is calculated from the sample sheet by our formula engine, the same one that grades the practice.

CellFormulaResultWhat it shows
E2=SORT(A2:A6)Desk lampspills 5 × 1Product names, A to Z
G2=SORT(A2:C6,3,-1)Monitor armspills 5 × 3The whole table by revenue, column 3, highest first
K2=INDEX(SORT(A2:C6,2,-1),1,1)USB hubSort by units, then take the first name

Try it live

This is the sample sheet. Change any number or text, or edit a formula, and the results update.

Show the sample data as a table
ProductUnitsRevenueA to ZBy revenue, highest firstMost units sold
Desk lamp48$1,872Desk lampMonitor arm22$1,958USB hub
Monitor arm22$1,958Laptop standLaptop stand35$1,890
Laptop stand35$1,890Monitor armDesk lamp48$1,872
USB hub61$1,769USB hubUSB hub61$1,769
Webcam17$1,173WebcamWebcam17$1,173

Practice SORT

From lesson 19, UNIQUE & SORT. Graded instantly, then re-checked on changed data.

Sorted rep list

In F2, list each rep once, sorted A to Z.

Common mistakes

What you seeWhy, and how to fix it
#SPILL!Something is in the cells the result needs. Clear everything below and to the right of the formula, or move it to an empty area.
The header row ends up in the middlearray included row 1. Start it on the first data row, such as A2:C6.
#VALUE!sort_index is bigger than the number of columns in array, such as 4 for a three-column range. Count from the left edge of array, not from column A.
#NAME?SORT needs Excel 2021, Excel 2024 or Microsoft 365. In older versions, sort a copy with Data > Sort.

Tips

  • To sort by two columns, use SORTBY, which takes several sort keys.
  • Combine with TAKE for a live top-3: =TAKE(SORT(A2:C6,3,-1),3).

Questions

How do I sort largest to smallest with a formula?

Set sort_order to -1: =SORT(A2:C6,3,-1) sorts by the third column from highest to lowest.

Does SORT change my original data?

No. It returns a sorted copy and the source stays as it is. That also means you can't type over the results; edit the source instead.

How do I sort by more than one column?

Use SORTBY: =SORTBY(A2:C6,B2:B6,1,C2:C6,-1) sorts by column B, then breaks ties by column C from highest to lowest.

Lessons that use SORT

Last reviewed October 2026. Every example result on this page is calculated live by the Spreadsheet Practice formula engine.