ExcelFormulas logoExcelFormulas.
Ask AI
Dynamic ArraysVerified QA Tested

SORTBY.

Sorts a range based on values in a separate range or array.

Category: Dynamic Arrays
ExcelExcel 365Excel 2021Google Sheets

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], ...)
Tip:Arguments wrapped in square brackets [like_this] are optional; all other arguments are required.

Formula arguments.

Every parameter accepted by the SORTBY function is detailed below.

arrayRequired

The range to sort and return.

Example value: A2:A5
by_array1Required

The criteria range to sort by.

Example value: B2:B5
sort_order1Optional

1 for Ascending (default), -1 for Descending.

Default: 1

Simple example.

Step-by-Step Scenario

Order Roster - Sort Names by Score

Extract only product names, sorted by their revenue column.

ProductRevenueSorted List
Product A120—
Product B500—
Product C310—
Applied Formula
=SORTBY(A2:A5, B2:B5, -1)
Expected Result:Product B

Evaluates SORTBY over the sample table cells, placing the verified output in cell C2.

Formula generator.

Full Generator Wizard

Customize the argument fields below to generate a tailored SORTBY formula ready to paste directly into your worksheet.

Generated FormulaReady to copy

Expected result behavior.

Returns "Product B" based on sample evaluation criteria and active cell references.

Sample Output:Product B
Output Type:Text String

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.
Compatibility Database

Platform & version compatibility.

Verified platform compatibility matrix based on actual spreadsheet calculation engine specifications.

Excel✓
Supported
Excel 365✓
Supported
Excel 2021✓
Supported
Excel 2019✕
No
Google Sheets✓
Supported
Microsoft Excel History & Version Availability

Introduced in Excel 365 and Excel 2021. Not available in Excel 2019.

Google Sheets Compatibility Notes

Supported in Google Sheets (uses SORTN or standard SORT with external array keys).

Frequently asked questions.

Technical Q&A
Can 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.