The SORT function is one of the most important excel functions for sorting data in ascending or descending order based on a selected column within the data.
Syntax
=SORT(array, [sort_index], [sort_order], [by_col])
Arguments
➡️Array: Required. The range or array to sort.
➡️Sort_index: Optional. The column index to use for sorting. The default is 1.
➡️Sort_order: Optional. 1 = Ascending, -1 = Descending. The default is ascending order.
➡️By_col: Optional. TRUE = sort by column. FALSE = sort by row. The default is FALSE.
🎯To sort data in ascending order by the first column, use this formula:
=SORT(B3:D11, 1, 1)
But what if we want to sort the data in ascending or descending order based on all columns, not just one column (if possible)?
In this case, we can use this formula:
=SORT(B3:D11, {1, 2, 3}, 1)
or
=SORT(
B3:D11,
SEQUENCE(, COUNTA(B15:D15), 1)
)