How to use SORT function in Excel?

The SORT function in Excel is used to sort the contents of a range or array. It allows for sorting based on one or more columns or rows. The basic syntax of the SORT function is as follows:

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

Here is a breakdown of the arguments:

  • array: This is the range or array that you want to sort. This is a required argument.
  • sort_index: This is an optional argument that specifies the column or row by which to sort. If sorting by columns, you would enter the column number. If sorting by rows, you would enter the row number. If omitted, the data is sorted by the first column (or row) of the array.
  • sort_order: This is an optional argument where you can specify the order of the sort. Use `1` for ascending order and `-1` for descending order. If omitted, the default is ascending order.
  • by_col: This is an optional argument that specifies the direction of the sort. Use `FALSE` or omit this argument to sort by rows (vertical), and `TRUE` to sort by columns (horizontal).

Examples

  • Sorting a Range by a Specific Column in Ascending Order

Suppose you have data in cells A1:C10 and you want to sort it by the second column (B) in ascending order. You would use:

   =SORT(A1:C10, 2, 1)
  • Sorting a Range by a Specific Column in Descending Order

To sort the same data by the second column (B) in descending order:

   =SORT(A1:C10, 2, -1)
  • Sorting by Rows Horizontally

If you want to sort a horizontal array from cells A1:Z1 by elements in ascending order:

   =SORT(A1:Z1, 1, 1, TRUE)

Tips

  • The SORT function is dynamic and will automatically update the sorted result if the source data changes.
  • Ensure you have Excel version 365 or later, as the SORT function is part of the newer array functions introduced in Excel.
  • If the SORT function doesn’t fit your needs, such as multi-level sorting or needing to sort in place, consider using the traditional sort feature found under the “Data” tab in Excel’s ribbon menu.

By using the SORT function, you can efficiently manage and organize your data in Excel, creating flexible, dynamic spreadsheets.

Unlock Your Potential

Excel

Basic - Advanced

Access

Access Basic - Advanced

Power BI

Power BI Basic - Advanced

Help us grow the project