Skip to content
AnIntent

How to Sort in Excel With a Formula Using the SORT Function

Use Excel's SORT function to build a sorted result that spills automatically and resizes when its source is an Excel Table.

AnIntent Editorial · · 2 min read

Hands typing on a laptop displaying a data spreadsheet
Photo by Gorilla ROI Data Connector on Unsplash
In this article
  1. Check that your Excel version has SORT
  2. The SORT syntax
  3. Sort a range with one formula
  4. Make the sorted list grow with your data
  5. Leave room for the spill
  6. Sorting by a specific column with SORTBY
Share this article

Excel's SORT function gives you a sorted result built by a formula, so you don't have to re-run a manual sort. This guide covers the basic SORT formula, how to keep the result growing with your data, and how much room to leave for it.

Check that your Excel version has SORT

Microsoft's SORT function page lists these versions:

  • Excel for Microsoft 365 (Windows and Mac)
  • Excel 2024 and Excel 2021 (Windows and Mac)
  • Excel for iPad, iPhone and Android tablets and phones

If your version isn't on that list, check Microsoft's page before building a workbook around the function.

The SORT syntax

Microsoft gives the syntax as:

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

Only array is required. It is the range or array you want sorted. The other three arguments are optional. According to Microsoft, when by_col is FALSE or left out, Excel sorts by row, which is what you want for a normal list with records in rows.

Sort a range with one formula

  1. Pick an empty cell where the sorted result should start, with enough empty space to the right and below it.
  2. Type the formula, pointing it at your data. For example:
=SORT(A2:D20)
  1. Press Enter.

The result spills. Microsoft says Excel creates the appropriately sized range when you press Enter, and the returned array is the same shape as the array argument. So if you sort four columns, the result is four columns wide with the same number of rows as your source.

Make the sorted list grow with your data

Keep the source data in an Excel Table and refer to it with structured references. Microsoft's page says that if the source is an Excel Table and you use structured references, the result resizes as rows are added or removed.

Leave room for the spill

Because the result spills into a block the same shape as your source, the cells it needs should be empty. Put the formula somewhere with clear space to the right and below, such as a separate sheet, rather than squeezing it next to other data.

Sorting by a specific column with SORTBY

Excel also has a related SORTBY function for sorting by a chosen column. This guide doesn't cover its arguments; check Microsoft's own SORTBY page for the full argument list and which versions support it before you rely on it in a shared workbook.

Common questions

Which Excel versions support the SORT function?

Microsoft's SORT page lists Excel for Microsoft 365 (Windows and Mac), Excel 2024 and 2021 (Windows and Mac), and Excel for iPad, iPhone and Android tablets and phones.

Will a SORT formula update when I add new rows?

Yes, if the source data is an Excel Table and you use structured references. Microsoft says the result then resizes as rows are added or removed.

Hands typing on a laptop displaying a data spreadsheet
How-to

How to Remove Extra Spaces in Excel With TRIM and CLEAN

Use TRIM to strip extra spaces, CLEAN to drop nonprinting characters, and LEN to find out which problem your cells actually have.

· 3 min

Keep reading