How it works.
SORTBY sorts a target range based on the values of another range, even if the sorting criteria range is not included in the returned output.
Formula syntax.
Standard Excel Notation=SORTBY(array, by_array1, [sort_order1], ...)[like_this] are optional; all other arguments are required.Formula arguments.
Every parameter accepted by the SORTBY function is detailed below.
The range to sort and return.
Example value:A2:A5The criteria range to sort by.
Example value:B2:B51 for Ascending (default), -1 for Descending.
Default: 1Simple example.
Step-by-Step ScenarioOrder Roster - Sort Names by Score
Extract only product names, sorted by their revenue column.
| Product | Revenue | Sorted List |
|---|---|---|
| Product A | 120 | — |
| Product B | 500 | — |
| Product C | 310 | — |
=SORTBY(A2:A5, B2:B5, -1)Evaluates SORTBY over the sample table cells, placing the verified output in cell C2.
Formula generator.
Full Generator WizardCustomize the argument fields below to generate a tailored SORTBY formula ready to paste directly into your worksheet.
=SORTBY()Expected result behavior.
Returns "Product B" based on sample evaluation criteria and active cell references.
Best Practices
- Can sort by multiple priority levels: =SORTBY(names, department, 1, salary, -1).
Common Mistakes
- The by_array must have the exact same number of rows as the target array or #VALUE! occurs.
Platform & version compatibility.
Verified platform compatibility matrix based on actual spreadsheet calculation engine specifications.
In Excel 2019, sort by secondary key in Data > Sort or use multiple RANK calculations.
Introduced in Excel 365 and Excel 2021. Not available in Excel 2019.
Supported in Google Sheets (uses SORTN or standard SORT with external array keys).
Frequently asked questions.
Technical Q&ACan I use SORTBY across different worksheets in Excel?↓
Yes. You can reference cells located on other sheets by including the sheet name followed by an exclamation mark, for example: =SORTBY(Sheet2!A2:A10). If the sheet name contains spaces, enclose it in single quotes: ='Q1 Report'!A2:A10.
What is the most common reason for errors in SORTBY?↓
The by_array must have the exact same number of rows as the target array or #VALUE! occurs.
Does SORTBY work identically in Google Sheets?↓
Yes, SORTBY is supported in both Microsoft Excel and Google Sheets with standard evaluation behavior.