Sortby
SORTBY Function¶
The SORTBY function in Excel allows you to sort the contents of a range or array based on the values in one or more
other ranges or arrays. This function is particularly useful when you need to sort one dataset according to the values
of another dataset.
Syntax¶
- array: The array or range to be sorted.
- by_array1: The first array or range to sort by.
- sort_order1: (Optional) The order to sort by. Use
1for ascending (default) and-1for descending. - by_array_n: (Optional) Additional arrays or ranges to sort by.
- sort_order_n: (Optional) The order to sort the additional arrays or ranges.
Examples¶
- Sort a range by a single criterion
To sort the range A2:B5 by the values in column B in ascending order:
- Sort a range by multiple criteria
To sort the range A2:C5 by the values in column B in ascending order and then by values in column C in
descending order:
Notes¶
- If the
arraysize does not match anyby_arraysize, Excel will return a#VALUE!error. - The
SORTBYfunction helps in arranging data dynamically and is particularly useful when combined with other functions likeFILTER.
Usage Tips¶
- Combine
SORTBYwithUNIQUEto get a sorted list of unique values. - Use in conjunction with
FILTERfor more complex data manipulation and analysis tasks.
By understanding and utilizing the SORTBY function, you can efficiently manage and analyze your data, making it a
powerful tool in your Excel toolkit.