How to Use SORT in Excel: Simple Guide with Examples
Use the
SORT function in Excel to arrange data in ascending or descending order by specifying the range, sort column, and order. The formula looks like =SORT(array, [sort_index], [sort_order], [by_col]), where you choose which column to sort and how.Syntax
The SORT function arranges data from a range or array. It has four parts:
- array: The data range you want to sort.
- sort_index (optional): The column number to sort by (1 for first column).
- sort_order (optional): Use 1 for ascending (smallest to largest) or -1 for descending (largest to smallest). Default is ascending.
- by_col (optional): Set TRUE to sort by columns instead of rows; default is FALSE (sort by rows).
excel
=SORT(array, [sort_index], [sort_order], [by_col])
Example
This example sorts a list of names and scores by the score column in descending order.
excel
A1:B5 contains: Name Score Anna 85 Ben 92 Cara 78 Dan 90 In cell D1, enter: =SORT(A2:B5, 2, -1) This sorts the data by the second column (Score) from highest to lowest.
Output
Ben 92
Dan 90
Anna 85
Cara 78
Common Pitfalls
Common mistakes when using SORT include:
- Not specifying
sort_indexcorrectly, which defaults to the first column and may not sort as expected. - Forgetting that
SORTreturns a new sorted array and does not change the original data. - Using
sort_ordervalues other than 1 or -1, which will cause errors. - Trying to sort by columns without setting
by_colto TRUE.
excel
Wrong: =SORT(A2:B5, 3) // Column 3 does not exist Right: =SORT(A2:B5, 2, 1) // Sort by second column ascending
Quick Reference
| Parameter | Description | Default |
|---|---|---|
| array | Range or array to sort | Required |
| sort_index | Column number to sort by | 1 |
| sort_order | 1 for ascending, -1 for descending | 1 |
| by_col | TRUE to sort by columns, FALSE by rows | FALSE |
Key Takeaways
SORT arranges data by rows or columns based on your chosen column and order.
Always specify the correct column number with sort_index to get expected results.
SORT outputs a new sorted array; it does not change the original data.
Use 1 for ascending and -1 for descending sort_order values only.
Set by_col to TRUE if you want to sort data horizontally by columns.