SORT function

SORT arranges array data in ascending or descending order by a specified column, returning a sorted copy as a dynamic array.

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

Generate a SORT formula

Describe what you need. The generator will reach for SORT where SORT is the right tool, and tell you when it is not.

How to get a better answer
  • Name your columns by letter and by header: "column F (Net Value)" beats "the amount column".
  • State every condition, including the negatives — "not cancelled" changes the formula's shape.
  • Say where the data starts if it is not row 1, and whether it will grow.
  • Check the settings above match your spreadsheet: the wrong argument separator is a syntax error on your machine.

Arguments

How SORT reads its arguments
arrayrequiredsort_indexoptionalsort_orderoptionalby_coloptionalSORT
ArgumentRequiredDescription
arrayRequiredThe data range or array to sort. Required. Must be a single contiguous block; can include headers.
sort_indexOptionalColumn number (1-based) to sort by. Optional; defaults to 1 if omitted. Must be a positive integer ≤ number of columns.
sort_orderOptional1 for ascending (A–Z, smallest to largest); -1 for descending. Optional; defaults to 1 if omitted.
by_colOptionalTRUE sorts across columns independently; FALSE (default) sorts down rows (usual behavior). Optional.

Returns

An array matching the input dimensions, with all rows reordered by the specified column.

Availability

Excel: 365 / 2021+ · Google Sheets: Supported

Worked examples

1. Sort sales orders by region alphabetically

Order IDRegionRepUnitsUnit PriceOrder Date
1001WestAlice524.991/15/2024
1002EastBob315.51/20/2024
1003WestCarol8122/1/2024
1004SouthAlice2452/5/2024
1005EastDavid622.52/10/2024
=SORT(A1:F5, 2, 1)

Result: Order IDRegionRepUnitsUnit PriceOrder Date1002EastBob315.51/20/20241005EastDavid622.52/10/20241004SouthAlice2452/5/20241001WestAlice524.991/15/20241003WestCarol8122/1/2024

SORT arranges the five data rows by column 2 (Region) in ascending alphabetical order: East, East, South, West, West. The complete row moves as a unit, preserving the relationship between Order ID, Rep, and other fields.

2. Sort sales orders by units sold, highest first

Order IDRegionRepUnitsUnit PriceOrder Date
1001WestAlice524.991/15/2024
1002EastBob315.51/20/2024
1003WestCarol8122/1/2024
1004SouthAlice2452/5/2024
1005EastDavid622.52/10/2024
=SORT(A1:F5, 4, -1)

Result: Order IDRegionRepUnitsUnit PriceOrder Date1003WestCarol8122/1/20241005EastDavid622.52/10/20241001WestAlice524.991/15/20241002EastBob315.51/20/20241004SouthAlice2452/5/2024

SORT arranges by column 4 (Units) in descending numerical order: 8, 6, 5, 3, 2. Using sort_order -1 reverses the default ascending direction, making this useful for identifying which orders had the largest volumes at a glance.

3. Sort sales orders by date, most recent first

Order IDRegionRepUnitsUnit PriceOrder Date
1001WestAlice524.991/15/2024
1002EastBob315.51/20/2024
1003WestCarol8122/1/2024
1004SouthAlice2452/5/2024
1005EastDavid622.52/10/2024
=SORT(A1:F5, 6, -1)

Result: Order IDRegionRepUnitsUnit PriceOrder Date1005EastDavid622.52/10/20241004SouthAlice2452/5/20241003WestCarol8122/1/20241002EastBob315.51/20/20241001WestAlice524.991/15/2024

SORT arranges by column 6 (Order Date) in descending date order, placing the most recent orders first. SORT automatically recognizes date values and sorts them chronologically, regardless of how they're formatted in the cell.

Common errors

Which SORT error are you seeing?
SORT returned an error#VALUE!
Verify sort_index matches your column count. Use 1 for the first column, 2 for the second, etc. Check that you haven't included an extra comma or invalid value.
#SPILL!
Clear sufficient empty cells adjacent to the formula location, or move the SORT formula to a region with enough blank space for the entire result array.
#N/A
Clean the source data by replacing #N/A errors with valid values or blanks. Use IFERROR to replace errors before sorting: =SORT(IFERROR(A1:F5, ""), 2, 1).
ErrorWhy it happensHow to fix it
#VALUE!The sort_index argument is not a positive integer, or exceeds the number of columns in the array (e.g., =SORT(A1:F5, 7, 1) when only 6 columns exist).Verify sort_index matches your column count. Use 1 for the first column, 2 for the second, etc. Check that you haven't included an extra comma or invalid value.
#SPILL!The sorted result would overwrite existing data in cells to the right or below where the formula is placed, and SORT cannot expand freely.Clear sufficient empty cells adjacent to the formula location, or move the SORT formula to a region with enough blank space for the entire result array.
#N/AThe array contains #N/A errors that cannot be ordered, or data types are too incompatible to sort (e.g., trying to sort formulas that return errors).Clean the source data by replacing #N/A errors with valid values or blanks. Use IFERROR to replace errors before sorting: =SORT(IFERROR(A1:F5, ""), 2, 1).

Tips and when to use something else

  • To sort by multiple columns, nest SORT formulas: =SORT(SORT(data, 3, 1), 2, 1) sorts first by column 3, then by column 2 for ties.
  • SORT creates a live dynamic array—if your source data changes, the sorted result updates automatically without touching the original.
  • When the result would overwrite headers, exclude headers from the sort range or place the formula in a separate area and reference it elsewhere.
  • For more complex sorting with named sort orders or when you need to sort by multiple columns with different orders, use SORTBY or create a pivot table instead.

Frequently asked questions

Why does SORT move my header row?
SORT treats all rows equally—headers are sorted alphabetically or numerically like data. Exclude headers from the array (use A2:F5 instead of A1:F5) or place the formula elsewhere and reference the sorted result. If headers must stay at the top, sort data-only rows separately.
Can I sort by multiple columns at once?
SORT sorts by one column. To sort by Region first, then Rep, use nested SORT: =SORT(SORT(A1:F5, 3, 1), 2, 1). For cleaner syntax with more control, use SORTBY instead.
What happens to blank cells when I sort?
Blanks appear first in ascending sorts (smallest value) and last in descending sorts (largest value). Clean your data before sorting, or use FILTER to exclude blanks: =SORT(FILTER(A1:F5, A2:A5<>""), 2, 1).
Is there a difference between SORT and manually sorting in Excel?
SORT is a formula that updates automatically when source data changes—manual sorting modifies the original range permanently. SORT also integrates easily into dashboards and linked reports, while manual sorting is a one-time action.

Need a different formula?

The full generator is not scoped to one function — describe any spreadsheet problem and it will pick.

Open the formula generator

Reviewed 2026-09-17