0
0
ExcelHow-ToBeginner ยท 3 min read

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_index correctly, which defaults to the first column and may not sort as expected.
  • Forgetting that SORT returns a new sorted array and does not change the original data.
  • Using sort_order values other than 1 or -1, which will cause errors.
  • Trying to sort by columns without setting by_col to 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

ParameterDescriptionDefault
arrayRange or array to sortRequired
sort_indexColumn number to sort by1
sort_order1 for ascending, -1 for descending1
by_colTRUE to sort by columns, FALSE by rowsFALSE
โœ…

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.