SORT

Sort a range or array by any column in ascending or descending order with the SORT function.

Lookup & Reference
|
Excel 2019+
|
Google Sheets Supported

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

The SORT function takes a range or array and returns it in sorted order. By default it sorts by the first column in ascending order, but you can pick any column (or row) and choose ascending or descending. Because SORT returns a dynamic array, the results spill automatically into neighboring cells and stay up to date when your source data changes.

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.

Examples

Mixed data types sort separately

Try sorting a column that mixes numbers and text. Notice that Excel groups all numbers first, then all text. They don't interleave. Edit a value to switch its type and watch the order change.

Spreadsheet editor

Sort filtered tasks by due date

Wrap FILTER inside SORT to get only high-priority tasks, ordered by due date. Change a priority to "Low" and watch it drop out of the sorted result.

Spreadsheet editor

Alphabetize unique categories

Nest UNIQUE inside SORT to pull out distinct values in alphabetical order. Add a new category in column B and see it appear in the sorted list automatically.

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.

Tips & notes

SORT is a dynamic array function available in Excel 2021, Excel for Microsoft 365, and Excel for the web. The output updates automatically when your source data changes. If you need to sort by multiple columns at once, consider SORTBY which accepts multiple sort keys in a single call.

Common questions

Can I sort by multiple columns with SORT?

SORT itself only sorts by one column at a time. To sort by multiple columns, nest SORT calls (sort by the secondary column first, then by the primary column), or use SORTBY which handles multiple sort keys in one formula.

What is the difference between SORT and SORTBY?

SORT identifies the sort column by its index number (1, 2, 3, etc.), while SORTBY references a separate range directly. SORTBY is more resilient when your table structure changes and supports sorting by multiple columns in a single call.

Does SORT change my original data?

No. SORT returns a new sorted array in a separate location. Your original range stays exactly as it is.