How to Use the SORT Function in Google Sheets
=SORT(range, sort_column, is_ascending). Use TRUE for A to Z or smallest first, and FALSE for descending order.
SORT vs the sort menu
The Data menu sorts your cells in place. SORT leaves the original data alone and returns a sorted copy somewhere else. When the source changes, the sorted copy updates automatically, which makes SORT ideal for leaderboards and live reports.
SORT syntax
=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
range: the data to sort. Leave the header row out.sort_column: the column to sort by, given as its position insiderange(1 for the first column). It can also be a separate range outsiderange, which must be a single column with the same number of rows.is_ascending:TRUEorFALSE. Per Google's page, FALSE sorts in descending order.- Extra pairs of
sort_columnandis_ascendingare optional and are used in order of priority.
Only the columns you name decide the order. The other columns are returned in the order they originally appear.
A step-by-step example
Here are four names and scores in cells A1:B5.
| A | B | |
|---|---|---|
| 1 | Name | Score |
| 2 | Cara | 67 |
| 3 | Ann | 82 |
| 4 | Dev | 91 |
| 5 | Ben | 54 |
=SORT(A2:B5, 2, FALSE)
This returns the rows ordered by the second column, highest first: Dev 91, Ann 82, Cara 67, Ben 54. Here is why: the 2 means the second column of the range (Score), and FALSE means descending. To sort alphabetically by name instead:
=SORT(A2:B5, 1, TRUE)
This returns Ann, Ben, Cara, Dev with their scores attached.
Sort by two columns
Add another pair of arguments for ties. =SORT(A2:B5, 2, FALSE, 1, TRUE) sorts by score first and uses the name to break ties.
Common mistakes
- Including the header row. It is sorted like any other row.
- Mixing up the column number. It counts from the first column of the range, not of the sheet.
- Blocked output. The sorted result spills into the cells below and to the right, so they must be empty.
Try it yourself
Use the table above (A1:B5). Type your formula into the box, starting with =, then press Check.
Exercise 1: Highest score first
Write a formula that returns A2:B5 sorted by the Score column, highest first.
Exercise 2: A to Z by name
Write a formula that returns A2:B5 sorted alphabetically by name.
What to learn next
- FILTER: pull out the rows that match.
- UNIQUE: remove duplicates from a list.
- QUERY: filter, group and sort with one formula.
- SORTN: return the top or bottom N rows.
Syntax and rules in this guide were checked against Google's SORT help page. See all guides.