SORT Function
Sorts a range or array (spills the result).
Syntax
Parameters
| Parameter | Description | Required |
|---|---|---|
| array | The range or array to sort. | Required |
| sort_index | The column (or row, when by_col is TRUE) number to sort by. Defaults to 1. | Optional |
| sort_order | 1 for ascending (default) or -1 for descending. | Optional |
| by_col | FALSE to sort down rows (default) or TRUE to sort across columns. | Optional |
Basic Example
Sort a list of numbers ascending
=SORT(A2:A10)With no extra arguments, SORT orders the first column ascending and spills the result.
Advanced Examples
Example 1: Sort a table by a specific column
Sort a table by the Score column (column 3) from highest to lowest.Use sort_index and descending order
=SORT(A2:C20, 3, -1)Example 2: Sort horizontally
Sort values across a single row left to right.Set by_col to TRUE
=SORT(A2:F2, , , TRUE)How SORT Works
SORT produces a dynamic array containing the sorted values of the input. By default it sorts the first column (or row) ascending. sort_index selects which column/row to sort by, sort_order is 1 (ascending) or -1 (descending), and by_col switches between sorting down rows and across columns. The result spills into neighboring empty cells.
Important Notes & Limitations
Available only in Microsoft 365 (and Excel 2021+); not in Excel 2019 and earlier.
Requires empty spill space below/right or it returns #SPILL!.
Sorts by a single key column at a time; use SORTBY for multiple sort keys.
Common Errors & Fixes
#SPILL! errorThere is no room for the spilled results.Fix: Clear the cells in the spill range.
#VALUE! errorsort_index points beyond the number of columns/rows.Fix: Make sure sort_index is within the array dimensions.
Download Practice File
SORT
sortPractice SORT with Real Data
Download a sample CSV file with pre-populated data and practice exercises for the SORT function. Works in both Excel and Google Sheets.
File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps
Related Tutorials
Master Excel Dynamic Arrays (Excel 365)
Learn how to use modern dynamic array functions like FILTER, SORT, UNIQUE, and SEQUENCE to transform your spreadsheets.
Excel Sales Dashboard: Build One That Updates Itself
Build an Excel sales dashboard that keeps itself current: one flat sales table, SUMIFS KPIs, XLOOKUP targets and FILTER drill-downs that grow with the data.