SORT

Return a range sorted by one of its columns, ascending or descending. The result spills and updates when the source changes.

Syntax

SORT(array, [sort_index], [sort_order])
Argument Required Description
array Required The range to sort.
sort_index Optional Which column to sort by, counting from 1. Defaults to 1.
sort_order Optional 1 (the default) for ascending, -1 for descending.

Examples

Every example below was executed against VisiGrid engine 0.54.0 — not transcribed from another vendor's documentation. Reproduce any of them with vgrid calc.

Formula Result Notes
=D1 Bo SORT(A2:B5,2,-1) in D1 sorts the table by score, highest first, and spills into D1:E4.
=E1 91
=D3 Ana Ana and Cy tie on 72 and keep their original order.
=D4 Cy

A sorted copy that stays sorted

Sorting with the menu rearranges the data once. SORT leaves the source alone and produces a sorted copy beside it, which re-sorts itself whenever the source changes — a leaderboard, a ranked list, the top of a report.

Ties keep their order

Rows with equal keys stay in the order they had in the source, in both directions. That makes a two-level sort possible in two steps: sort the source by the secondary key, then SORT the result by the primary one.

Spills

The result fills as many cells as the source has. If anything is in the way, the formula shows #SPILL! rather than overwriting it.

Excel compatibility

Matches Excel's SORT for sort_index and sort_order (1 or -1). TRUE and FALSE are also accepted as the order, for ascending and descending.

Related functions

Last updated