Skip to main content

Excel SORTBY Function

The SORTBY function sorts the contents of one range or array based on the values in a corresponding range or array, no matter the corresponding range or array is included in the range or array to be sorted or not.

Note: The SORTBY function is only available in Excel for Microsoft 365, Excel 2021 or newer versions of Excel, and Excel for the web.

sortby function 1


=SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], )


  • array (required): The range or array to sort
  • by_array1 (required): The range or array to sort by.
  • [sort_order1] (optional): A number indicating the sort order:
    • 1 or omitted, to sort in ascending order;
    • -1, to sort in descending order.
  • [by_array2, sort_order2], … (optional): Additional array and sort order pairs.

Return Value

The SORTBY function returns an array.

Function Notes

  • array can be supplied as a row of values, a column of values, or a combination of rows and columns of values.
  • A by_array argument should be supplied as one row or one column, and it must have dimensions compatible with array.
  • The dimensions of the returned array are the same as the array argument. If one or more cells in the spill range are not empty, the #SPILL! error will be returned.
  • If you want to omit the sort_order argument in additional array and sort order pairs, you should keep the comma (,), e.g. [by_array2,].
  • SORTBY can be used between different workbooks. However, make sure the referenced workbooks are open. Otherwise, a #REF! error will be returned if you refresh the result cell.
  • The results of SORTBY are dynamic, meaning that they update automatically when values in the source data change. However, the results will not be updated if you add new entries to array. To fix this, you should use structured references as array argument.


Suppose that you have score ranking in a table as shown in the screenshot below. To sort the table by classes (from class A to class B) and then by scores (from highest to lowest), and not showing scores, you should set the array argument to the columns you want to show, that is C4:E15, and set by_array1 to the class column and leave the sort_order empty since it defaults to sort Alphabetically. Then you should add an additional array and sort order pair: B4:B15,-1. Please copy or enter the formula below in the top left cell of the result table and then press Enter to get the result:


sortby function 2

Related functions

Excel SORT Function

The SORT function sorts the contents of a range or array in ascending or descending order.

Excel UNIQUE Function

The UNIQUE function extracts unique values from a range of data. The data can include text, numbers, dates, error values, etc.

Excel FILTER Function

The FILTER function filters a range of data and dynamically returns the matching results according to the criteria you specify.

The Best Office Productivity Tools

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations