SORT function - Microsoft Support (original) (raw)

Applies ToExcel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2024 Excel 2024 for Mac Excel 2021 Excel 2021 for Mac Excel for iPad Excel for iPhone Excel for Android tablets Excel for Android phones Microsoft Office Microsoft365.com

The SORT function sorts the contents of a range or array.

In this example, we're sorting by Region, Sales Rep, and Product individually with =SORT(A2:A17), copied across cells F2, H2, and J2.

Use the SORT function to sort ranges of data. Here we're using =SORT(A2:A17) to sort Region, then copied to cells H2 & J2 to sort Sales Rep name, and Product.

SORT returns a sorted array of the elements in an array. The returned array is the same shape as the provided array argument.

=SORT(array,[sort_index],[sort_order],[by_col])

Argument Description
array Required The range, or array to sort
[sort_index] Optional A number indicating the row or column to sort by
[sort_order] Optional A number indicating the desired sort order; 1 for ascending order (default), -1 for descending order
[by_col] Optional A logical value indicating the desired sort direction; FALSE to sort by row (default), TRUE to sort by column

Notes:

Examples

Sort a range of values in descending order.

Sort a range of values in descending order.

Use SORT and FILTER together to sort a range in ascending order, and limit it to values over 5,000.

Use SORT and FILTER together to sort a range in ascending order, and limit it to values over 5,000.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in Communities.

See Also

FILTER function

RANDARRAY function

SEQUENCE function

SORTBY function

UNIQUE function

#SPILL! errors in Excel

Dynamic arrays and spilled array behavior

Implicit intersection operator: @

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.