Excel - SORT Function



SORT Function

The EXCEL SORT function sorts the items of an array, either column-wise or row-wise, in ascending or descending order. It is categorized in the Dynamic array functions in Microsoft Excel. The SORT function retrieves the dynamic array whose elements automatically spill to the adjacent cells when necessary.

These exclusive functions enhance organizational productivity and improve readability when dealing with lengthy text. When dealing with lists in Excel, using SORT function enables you to structure information more logically by sorting the data ideally as desired. This reduces clutter and confusion while allowing for a more transparent presentation and understanding. The SORT function is not exclusive to older versions of Microsoft Excel.

Compatibility

This advanced Excel function is compatible with the following versions of Microsoft Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web
  • Excel 2024
  • Excel 2024 for Mac
  • Excel 2021
  • Excel 2021 for Mac
  • Excel for iPad
  • Excel for iPhone
  • Excel for Android tablets
  • Excel for Android phones

Syntax

The syntax of SORT function is as follows −

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

Arguments

You can use the following arguments with the SORT function −

Argument Description Required / Optional
array It denotes the cell range or array that you want to sort. Required
sort_index A numeric value representing a row or column index to enable the sorting of its elements. Optional
sort_order Its value can be 1(non-descending order) or -1(non-ascending order). By default, the SORT function assumes its value as 1. Optional
by_col It specifies the logical value as either True or False.
If the by_col value equals TRUE, the SORT function will sort the array elements by column; otherwise, it sorts by row.
Optional

Points to Remember

  • To implement this excellent SORT function, you must install the latest version of Excel in the system. Otherwise, the SORT function will not execute.
  • If the second argument, sort_index, contains an invalid column or incorrect row number, the SORT function will return the #VALUE error.
  • If the third argument sort_order value is other than 1 and -1, then the SORT function will return the #VALUE error.

Examples of SORT Function

Practice the following examples to learn the use of the SORT function in Excel.

Example 1

The SORT function in Excel is use to sort a range or array of data based on specified criteria.

Solution

Step 1 − Open the worksheet containing the data cells requiring the sorting of data. First, write the two-column heading named "Employee Name" and "Salary" in the given table and enter entries as shown below image −

SORT Function in Excel

Step 2 − After that, enter the formula "=SORT(Table1[Employee Name],1,1)" in the D1 cell and press the Enter tab as highlighted in below image −

SORT Function in Excel 1

Therefore, you can use the SORT function to sort the employee names in ascending order as shown below −

SORT Function in Excel 2

Suppose we wish to list the employee name in descending form; in that case, the SORT formula becomes =SORT(Table2[Employee Name]),1,-1) in the D1 cell.

SORT Function in Excel 3

Therefore, the SORT function returns the list of employee names in descending order.

SORT Function in Excel 4

Example 2

Use of SORT and FILTER functions in Microsoft Excel

Solution

You can filter the data, apply some constraints, and sort it using the SORT and FILTER functions.

Lets say if you display only those rows in the sample dataset whose salary> 32000. Go to the G1 cell and enter the formula =SORT(FILTER(Table1,Table1[Salary]>E4,""),1,-1,TRUE) and press the Enter tab.

SORT and FILTER Function in Excel

Therefore, we can ideally use the sort function and filter function to obtain the three rows of the arrays whose salaries are greater than 32000.

SORT and FILTER Function in Excel
Advertisements