# Excel SORTBY Function

Summary

The Excel SORTBY function sorts the contents of a range or array based on the values from another range or array. The range or array used to sort does not need to appear in results.

Purpose

Sorts range or array by column

Return value

Sorted array

Syntax

=SORTBY (array, by_array, [sort_order], [array/order], ...)

Arguments

**array**- Range or array to sort.**by_array**- Range or array to sort by.**sort_order**- [optional] Sort order. 1 = ascending (default), -1 = descending.**array/order**- [optional] Additional array and sort order pairs.

Usage notes

The Excel SORTBY function sorts the contents of a range or array based on the values from another range or array. The range or array used to sort does not need to appear in the source data. In the example shown, the formula in E5 is:

=SORTBY(B5:B14,C5:C14,-1) // sort by grades descending

The output in E5:E14 is the list of names sorted by scores in descending order. To sort by grades in ascending order use:

=SORTBY(B5:B14,C5:C14,1) // sort by grades ascending

### Notes

- All arguments must have compatible dimensions, i.e.
*array*and*by_array1*must contain the same number of rows. - The by_array arguments can only be one row or one column.
- The sort_order argument can only be -1 (descending) or 1 (ascending). If no value is provided, SORTBY will sort in ascending order.

SORTBY is a new function available in Office 365 only.

See also

## Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.