1. Home
  2. Functions
  3. Array
  4. SORT

SORT function

Sorts the rows or columns of a range or array.

Syntax

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

Arguments

ArgumentRequiredDescription
arrayRequiredThe range or array to sort
sort_indexOptionalWhich column (or row) to sort by (default 1)
sort_orderOptional1 ascending (default), -1 descending
by_colOptionalFALSE (default) sorts rows, TRUE sorts columns

How to use SORT

When SORT returns more than one value, the result spills into the cells below and to the right. Keep those cells empty, or you get #SPILL!.

SORT takes 1 required argument and 3 optional arguments. Type =SORT( in a cell and SheetsBat shows the arguments as you go. Optional arguments are shown in square brackets; leave them out to use their default.

Examples

Each result below was calculated by the SheetsBat formula engine.

=SORT({3;1;2})Result 3 by 1 array
Spilled result
A
11
22
33
=SORT({"b",2;"a",1;"c",3}, 2, -1)Result 3 by 2 array
Spilled result
AB
1c3
2b2
3a1
=SORT({1;2}, 3)Result #VALUE!

Every formula, right in your browser

SheetsBat calculates 536 functions, with charts, pivot tables and live collaboration. Free to start.