Function · Dynamic arrays

Excel SORT function

The Excel SORT function returns a range sorted by one of its columns and spills the rows. The four utility bills, sorted by amount, start with April's $88.10.

Microsoft 365, Excel 2021, Excel 2024, and Excel for the web. Also in Google Sheets.

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

SORT
=SORT(A2:B5,2,1)

Arguments

NameRequiredWhat to pass
arrayRequiredThe rows to sort, including the column you sort by.
sort_indexOptionalWhich column to sort by, counting the first column of array as 1. The default is 1.
sort_orderOptional1, the default, is ascending. -1 is descending.
by_colOptionalFALSE, the default, sorts rows. TRUE sorts columns left to right.

Examples

The four utility bills from smallest to largest

=SORT(A2:B5,2,1)

Result Apr $88.10, Feb $96.20, Mar $118.45, Jan $143.60

=SORT(A2:B5,2,1)D2
Bills
ABCDE
1MonthBillMonthBill
2Jan143.60Apr88.10
3Feb96.20Feb96.20
4Mar118.45Mar118.45
5Apr88.10Jan143.60
A picture of the sheet, not a live calculator. D2:E5 is the spill. The source in A2:B5 is left in its original order.

SORT returns a new list. It does not rearrange the cells you already have. The four utility bills sorted by the amount column, smallest first, are April $88.10, February $96.20, March $118.45, and January $143.60. The months in column A stay where they were. The spill in D2:E5 is the sorted copy.

sort_index 2 is the bill, because the array starts at column A. sort_order 1 is ascending and -1 is descending, so -1 would put January first. Text sorts alphabetically. A header inside the array sorts with the data, which is why this range starts at row 2. Excel 2019 does not have SORT. The Data tab’s Sort command is the one that rewrites the sheet in place.