SORT returns a sorted copy of a range, ordered by one or more columns, without touching the original data. Because it is a formula, the sorted view updates by itself when the source changes, unlike the menu's Data > Sort range, which rearranges the cells in place once.
Syntax
=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
range: The data to sort.sort_column: The column to sort by, given as a number within the range (1is the first column ofrange), or as a separate range of the same height.is_ascending:TRUEfor A to Z / smallest first,FALSEfor Z to A / largest first. This argument is required.- Further pairs of
sort_column/is_ascendingadd tie-breaker columns.
Basic examples
With names in A2:A100:
=SORT(A2:A100, 1, TRUE)
Sorts the list alphabetically.
With a table in A2:C100 (Name, Department, Salary):
=SORT(A2:C100, 3, FALSE)
Sorts the whole table by salary, highest first. Every row stays intact: names and departments move with their salaries.
Sorting by several columns
Add more pairs for tie-breakers. Sort by department A to Z, then by salary highest first within each department:
=SORT(A2:C100, 2, TRUE, 3, FALSE)
Sorting by a column outside the range
sort_column can be a separate range of the same height as range. That lets you sort one column by another without returning the sorting column:
=SORT(A2:A100, B2:B100, FALSE)
This returns the names from column A, ordered by the values in column B.
Sorting by a calculated value
You can sort by an expression too, which means no helper column is needed. For example, sorting by the length of each name:
=SORT(A2:A100, ARRAYFORMULA(LEN(A2:A100)), TRUE)
Or sorting by the last word in a full name:
=SORT(A2:A100, ARRAYFORMULA(REGEXEXTRACT(A2:A100, "\S+$")), TRUE)
Combining SORT with other functions
SORT is most useful as one step in a chain:
- Filter, then sort:
=SORT(FILTER(A2:C100, B2:B100 = "Sales"), 3, FALSE) - Unique values, sorted:
=SORT(UNIQUE(A2:A100)) - Top 5 values:
=ARRAY_CONSTRAIN(SORT(A2:C100, 3, FALSE), 5, 3).ARRAY_CONSTRAINlimits the output to 5 rows and 3 columns.SORTNdoes the same in one step. - Sort several ranges together:
=SORT({A2:C50; E2:G50}, 1, TRUE)stacks two tables, then sorts the result.
How SORT handles different data
- Numbers sort numerically, so
2comes before10. - Text sorts alphabetically and is not case-sensitive.
- Mixed data in a column sorts numbers first, then text, then booleans, with blanks last. If numbers are stored as text, they sort as text (
"10"before"2"). Convert them withVALUEfirst. - Dates sort chronologically when they are real dates, not text that looks like a date.
Common errors
#VALUE!... "Sort column ... exceeds the range".sort_columnis larger than the number of columns inrange. InSORT(A2:C100, 4, TRUE)there is no fourth column.#VALUE!with a separate sort range. The sort range does not have the same number of rows asrange.#REF!: Array result was not expanded. Something is blocking the cells the result needs. Clear the area below and to the right.- Headers sorted into the data. Leave the header row out of
range(start at row 2) and put the headers above the formula separately.
SORT vs. SORTN vs. the sort menu
Use SORT when you want a live, formula-driven sorted copy. Use SORTN when you only want the top N rows. Use Data > Sort range when you want to physically reorder the cells and do not need the data to stay linked.
Frequently asked questions
Does SORT change the original data? No. It only creates a sorted copy.
Can I sort descending without typing FALSE? The third argument is required, so you must give TRUE or FALSE. Numbers also work: 0 is FALSE and any other number is TRUE.
Is there a way to sort a row horizontally? Yes. Wrap it in TRANSPOSE: =TRANSPOSE(SORT(TRANSPOSE(A1:H1))).
Related Functions
SORTN: Returns the first N rows of a sorted range.FILTER: Returns the rows that meet a condition.UNIQUE: Returns the distinct rows of a range.QUERY: Filter, sort and aggregate in a single formula withorder by.ARRAYFORMULA: Applies a formula to a whole range.