SORT
Sort a range or array by any column in ascending or descending order with the SORT function.
Spreadsheet editor
Spreadsheet editor
Syntax
=SORT(array, [sort_index], [sort_order], [by_col])
Returns: Array Arguments
| Argument | Required | Description |
|---|---|---|
| array | Yes | The range or array of data to be sorted. |
| sort_index | No | The column number or row number to sort by. Defaults to 1 if omitted. |
| sort_order | No | The order in which to sort: 1 (ascending) or -1 (descending). Defaults to 1 if omitted. |
| by_col | No | A logical value specifying whether to sort by column (TRUE) or by row (FALSE). Defaults to FALSE if omitted. |
About
Use SORT when you need a live, sorted view of your data without rearranging the original range. It works well for ranked lists, leaderboards, or any table where order matters. For more flexibility, try SORTBY instead, which lets you sort by a separate range rather than a column index. You can also combine SORT with FILTER to sort a filtered subset, or wrap it around UNIQUE to sort deduplicated results.
Keep in mind that SORT uses a numeric index to identify the sort column, so adding or removing columns in your data can shift which column gets sorted. If your table structure changes often, SORTBY is a safer choice because it references the sort range directly.
Exercises using SORT
FILTER with SORT for a live leaderboard
IntermediateNest SORT inside FILTER to build a dynamic leaderboard that shows only salespeople who have exceeded their quota, ranked by total sales descending.
Open exerciseSort employees by hire date with SORT
IntermediateUse SORT to return a live copy of a table ordered by date.
Open exerciseUNIQUE with SORT for a department list
IntermediateCombine UNIQUE and SORT to create a clean, alphabetized list of distinct department names for a reporting summary.
Open exerciseLET with nested dynamic arrays
AdvancedBuild one readable spill formula that creates a merchandising snapshot by filtering, sorting, and returning selected review columns.
Open exerciseExamples
Mixed data types sort separately
Spreadsheet editor
Sort filtered tasks by due date
Spreadsheet editor
Alphabetize unique categories
Spreadsheet editor
Watch out for
Column index shifts when columns are added
You sort by column 3, then insert a new column before it. Now SORT is sorting by the wrong column.
→ Use SORTBY instead, which references the sort range directly and is not affected by column insertions or deletions.
Spill error from blocked cells
The formula returns a #SPILL! error because cells in the spill range already contain data.
→ Clear the cells below and to the right of the SORT formula so the dynamic array has room to expand.
Unexpected results with mixed data types
A column contains both numbers and text, and the sort order looks wrong because Excel sorts numbers and text separately.
→ Make sure the sort column contains a consistent data type. Convert text-formatted numbers to actual numbers if needed.