ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Comparisons
  3. SORT vs SORTBY in Excel: Which Dynamic Sort

SORT vs SORTBY in Excel: Which Dynamic Sort

By ExcelReady Team·Updated November 1, 2026·8 min read

The short answer

SORT orders a range by one of its own columns, chosen by position number: =SORT(A2:C6,2,-1) sorts by the second column, largest first. SORTBY orders a range by any range you point to, even one you don't return: =SORTBY(A2:A6,B2:B6,-1). Use SORT for quick single sorts and SORTBY for multi-level sorts or sorting by hidden or calculated values.

Key takeaways

  • SORT picks the sort column by number; SORTBY picks it by reference, so it survives inserted columns.
  • SORTBY can sort by a column that isn't in the result, such as names ordered by score.
  • For several sort levels, SORTBY takes simple pairs: range, order, range, order.
  • Both spill results into neighbouring cells and need Excel 2021, Excel for the web or Microsoft 365.
On this page+
  1. SORT vs SORTBY at a glance
  2. How SORT works
  3. How SORTBY works
  4. The same sorts done both ways
  5. When to use SORT
  6. When to use SORTBY
  7. Common mistakes with SORT and SORTBY
  8. Our recommendation
  9. Practise it

The short answer to SORT vs SORTBY in Excel: SORT orders a range by one of its own columns, which you choose by number, while SORTBY orders a range by any other range you point to, even one you don't return. Both create a live, sorted copy that updates when the data changes. This comparison is for anyone using Excel 2021 or Microsoft 365 who wants sorted lists, leaderboards or top-N reports without clicking the Sort button every time.

SORT vs SORTBY at a glance#

SORT is shorter for simple sorts; SORTBY is more flexible and easier to read for anything more.

FeatureSORTSORTBY
Syntax=SORT(array, [sort_index], [sort_order], [by_col])=SORTBY(array, by_array1, [sort_order1], ...)
How you choose the sort columnBy position number (1, 2, 3)By reference (B2:B6)
Sort by a column not in the resultNoYes
Multi-level sortArray constants like {3,2} and {1,-1}Simple pairs: range, order, range, order
Sort by a calculationNoYes, such as LEN(A2:A6)
Survives a column inserted inside the dataNo, the number can point to the wrong columnYes, the reference adjusts
Default orderAscending, by the first columnAscending
Sort across columns instead of rowsYes, with by_colYes, with a row as by_array
Excel versionsExcel 2021, 2024, web, Microsoft 365Excel 2021, 2024, web, Microsoft 365

Spilling means a formula in one cell fills the cells next to it with results. Both functions spill, so leave empty space below and to the right, or you get a #SPILL! error.

How SORT works#

SORT takes a range and returns it sorted by one of its columns.

Excel formula
=SORT(A2:C6)
=SORT(A2:C6,2,-1)

The first sorts by the first column, A to Z. The second sorts by column 2 of the range, with -1 meaning descending (largest first). Use 1 or leave the order out for ascending.

The sort column is a position inside the range, not a column letter. In A2:C6, 2 means column B. If the range were B2:D6, 2 would mean column C. The SORT function guide explains every argument.

How SORTBY works#

SORTBY takes the range to return, then one or more pairs of "sort by this range, in this order".

Excel formula
=SORTBY(A2:C6,B2:B6,-1)
=SORTBY(A2:A6,B2:B6,-1)

The first returns the whole table sorted by score, highest first, just like the SORT example. The second returns only the names, still ordered by score. The score column is used for sorting but isn't shown. SORT can't do that, because it can only sort by a column inside the range it returns.

The sort-by range must have the same number of rows as the range you return, or SORTBY returns #VALUE!.

The same sorts done both ways#

Here is a small team scoreboard:

ABC
1NameScoreTeam
2Priya82Red
3Tom95Blue
4Lena77Red
5Kofi88Blue
6Mei91Red

Task 1: whole table by score, highest first#

Excel formula
=SORT(A2:C6,2,-1)
=SORTBY(A2:C6,B2:B6,-1)

Both return Tom 95, Mei 91, Kofi 88, Priya 82, Lena 77, with their teams. For one sort level, SORT is a little shorter.

Task 2: names only, by score#

Excel formula
=SORTBY(A2:A6,B2:B6,-1)

This spills Tom, Mei, Kofi, Priya, Lena into one column. With SORT, you would have to sort the whole table and then pick out the names with another function.

Task 3: by team, then by score#

Excel formula
=SORT(A2:C6,{3,2},{1,-1})
=SORTBY(A2:C6,C2:C6,1,B2:B6,-1)

Both return Blue first (Tom 95, Kofi 88), then Red (Mei 91, Priya 82, Lena 77). The SORT version packs the column numbers and orders into curly-bracket lists, which is easy to mistype. The SORTBY version reads like a sentence: by team ascending, then by score descending. The guide on sorting by multiple columns has more examples.

Task 4: the top scorer only#

Excel formula
=INDEX(SORTBY(A2:A6,B2:B6,-1),1)

This returns Tom. INDEX takes the first item from the sorted list. Change 1 to 2 for the runner-up.

Task 5: one team, sorted, and a top three#

Both functions combine well with FILTER. To list only the Red team, highest score first:

Excel formula
=SORT(FILTER(A2:C6,C2:C6="Red"),2,-1)

This returns Mei 91, Priya 82 and Lena 77. FILTER keeps the Red rows, then SORT orders them by the second column. The SORTBY version needs the filter twice, once for the data and once for the sort key, so SORT is the neater choice here.

For a top three in Microsoft 365 or Excel 2024, TAKE keeps the first rows of a sorted result:

Excel formula
=TAKE(SORTBY(A2:B6,B2:B6,-1),3)

This spills Tom 95, Mei 91 and Kofi 88. In Excel 2021, which has no TAKE, use =INDEX(SORTBY(A2:B6,B2:B6,-1),SEQUENCE(3),{1,2}) for the same result.

When to use SORT#

Use SORT when you want a simple, one-level sort of a whole table. It fits:

  • Alphabetical lists: =SORT(A2:A50) for a sorted list of names.
  • A whole table by one column, such as products by price.
  • Combining with other dynamic functions, such as =SORT(UNIQUE(A2:A50)) for a sorted list of unique values.
  • Sorting across columns with the by_col argument, for data laid out in rows.
  • Sorting the result of another formula, such as a FILTER, where the columns are already known and a position number is quicker than repeating a range.
  • Drop-down source lists, where a sorted, spilled list of options keeps a data validation list in order as new items are added.

When to use SORTBY#

Use SORTBY whenever the sort needs more than one level or a column you don't want to show. It fits:

  • Multi-level sorts, such as region, then sales.
  • Leaderboards that show names only, sorted by a score you leave out.
  • Sorting by a calculation, such as name length: =SORTBY(A2:A6,LEN(A2:A6)).
  • Files where columns may be inserted later, because references adjust and position numbers don't.
  • Custom orders, such as High, Medium, Low, using MATCH against a list. See custom sort orders.

The comparison of SORT and SORTBY covers more patterns, and the Sort button vs the SORT function explains when a one-off manual sort is better.

Common mistakes with SORT and SORTBY#

  1. Using a column letter as sort_index. =SORT(A2:C6,"B") doesn't work. Use the position number, 2.
  2. Mismatched sizes in SORTBY. The sort-by range must have the same number of rows as the returned range, or you get #VALUE!.
  3. Including the header row. =SORT(A1:C6) sorts the header in with the data. Start the range on the first data row.
  4. Blocking the spill range. Anything typed below or beside the formula causes #SPILL!. Clear the cells.
  5. Forgetting -1 for descending. Both functions sort ascending unless you ask for -1.
  6. Using them in Excel 2019 or earlier. The formula shows #NAME?. Use the Sort button there, as explained in how to sort data in Excel.

Our recommendation#

Use SORT for quick, one-level sorts of a whole table, where its short syntax is an advantage. Use SORTBY for everything else: multi-level sorts, results that leave out the sort column, sorting by a calculation, and any file where columns might move. If you only want to learn one, learn SORTBY, because it can do everything SORT does and its references are easier to read and check.

In short: SORT for simple sorts, SORTBY for anything with more than one level or a hidden key.

Practise it#

Try the exercise on this page: find the top scorer with SORTBY and INDEX. Then practise the SORT function in a live spreadsheet: you type each formula, and it checks your answer instantly.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

In E2, find the name of the top scorer: use SORTBY to sort the names (A2:A6) by score (B2:B6) from highest to lowest, and wrap it in INDEX to return just the first name.

fx
ABCDEF
1
Name
Score
Team
2
Priya
82
Red
Top scorer
3
Tom
95
Blue
4
Lena
77
Red
5
Kofi
88
Blue
6
Mei
91
Red
7
8
9

Tip: SORTBY(A2:A6,B2:B6,-1) lists names from highest to lowest score. INDEX(...,1) takes the first one.

Practise this in a lesson

LessonSORT: order data with a formulaSort a table by any column, ascending or descending, and combine SORT with FILTER and UNIQUE.Function guideSORTSort a range with a formula using Excel's SORT. Sort by any column, highest first, or combined with FILTER. Includes a live exercise.

Frequently asked questions

What is the difference between SORT and SORTBY in Excel?

+

SORT sorts a range by one of its own columns, which you choose by position number. SORTBY sorts a range by one or more other ranges that you reference directly, and those ranges don't have to be part of the result.

Can SORT sort by more than one column?

+

Yes, with array constants: =SORT(A2:C6,{3,2},{1,-1}) sorts by column 3 ascending, then column 2 descending. SORTBY does the same with clearer pairs: =SORTBY(A2:C6,C2:C6,1,B2:B6,-1).

Which Excel versions have SORT and SORTBY?

+

Both are dynamic array functions available in Excel 2021, Excel 2024, Excel for the web and Microsoft 365. They are not in Excel 2019 or earlier.

Why does SORTBY return #VALUE!?

+

The range you sort by must have the same number of rows as the range you return. If one is A2:A6 and the other is B2:B7, SORTBY returns #VALUE!.

Does SORT change my original data?

+

No. SORT and SORTBY return a sorted copy in new cells. The original data stays in its order, and the copy updates when the original changes.

Sources

  • SORTBY function - Microsoft Support
  • SORT function - Microsoft Support
  • Dynamic array formulas and spilled array behavior - Microsoft Support

Written and checked by the ExcelReady Team. First published November 1, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. SORT vs SORTBY at a glance
  2. How SORT works
  3. How SORTBY works
  4. The same sorts done both ways
  5. When to use SORT
  6. When to use SORTBY
  7. Common mistakes with SORT and SORTBY
  8. Our recommendation
  9. Practise it

Keep reading

Dynamic arrays· 6 min read

SORT and SORTBY in Excel

SORT returns a sorted copy of a range: =SORT(A2:C9,3,-1) sorts by the 3rd column, largest first. SORTBY sorts one range by the values in another, so the column you sort by doesn't have to be in the result, and it handles several sort levels. Both leave the original data unchanged and need Excel 2021, Excel 2024 or Microsoft 365.

Dynamic arrays· 6 min read

Sort by Multiple Columns in Excel (Formula and Menu)

To sort by multiple columns in Excel, go to Data > Sort, pick the first column in Sort by, then click Add Level and pick the second column in Then by. For a live result, use a formula instead: =SORTBY(A2:C9,A2:A9,1,C2:C9,-1) sorts by column A from A to Z, then by column C from largest to smallest.

Comparisons· 7 min read

Sort Button vs SORT Function in Excel

The Sort button on the Data tab rearranges the rows of your table in place, once, and works in every version of Excel. The SORT function leaves the original data alone and returns a sorted copy that updates when the data changes, but it needs Excel 2021, Excel 2024, Microsoft 365 or Excel for the web.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free