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


Syntax

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


Arguments

  • 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.

Example

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(C4:E15,C4:C15,,B4:B15,-1)

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

Kutools for Excel - Helps You To Stand Out From Crowd

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ...
Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup...
Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List...
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...

Description


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