Quick Answer

SORT Function

Sorts a range or array (spills the result).

✓ Excel✓ Google SheetsExcel Microsoft 365

Syntax

SORT
(array, [sort_index], [sort_order], [by_col])

Parameters

ParameterDescriptionRequired
arrayThe range or array to sort.Required
sort_indexThe column (or row, when by_col is TRUE) number to sort by. Defaults to 1.Optional
sort_order1 for ascending (default) or -1 for descending.Optional
by_colFALSE to sort down rows (default) or TRUE to sort across columns.Optional

Basic Example

Sort a list of numbers ascending

=SORT(A2:A10)
ResultSorted list of the values in A2:A10, smallest to largest

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)
Result: The rows of A2:C20 reordered by Score, highest first
sort_index 3 picks the third column and -1 sorts it descending.

Example 2: Sort horizontally

Sort values across a single row left to right.

Set by_col to TRUE

=SORT(A2:F2, , , TRUE)
Result: The cells A2:F2 reordered into ascending order
by_col TRUE makes SORT sort across columns instead of down rows.

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.

1
Select the source
Pick the range or array to sort.
2
Add sort options
Optionally supply sort_index and sort_order.
3
Ensure spill space
Leave empty cells below/right for the results.

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

Practice 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.

Works in Google SheetsCompatible with ExcelIncludes exercises

File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps

Related Tutorials

Frequently Asked Questions

Is SORT available in Google Sheets?
Yes, SORT is a native function in Google Sheets.
How do I sort descending?
Add -1 as the sort_order argument, e.g. =SORT(A2:A10, 1, -1).
Can I sort by multiple columns?
Use SORTBY for multi-key sorting, or supply multiple columns in Sheets' SORT.