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

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Dynamic arrays
  3. Sort by a Custom Order With a Formula

Sort by a Custom Order With a Formula

By ExcelReady Team·Updated November 2, 2026·6 min read

The short answer

To sort by a custom list with a formula, use SORTBY with MATCH: =SORTBY(A2:C7,MATCH(B2:B7,E2:E4,0)). MATCH turns each value into its position in your list (High = 1, Medium = 2, Low = 3), and SORTBY orders the rows by those numbers. SORTBY needs Excel 2021 or Microsoft 365; older versions need a helper column.

Key takeaways

  • SORT and SORTBY sort A to Z or by size. For your own order, sort by each value's position in a custom list.
  • MATCH(B2:B7,E2:E4,0) turns each value into its position in the list, and SORTBY sorts by those positions.
  • Add a second pair to SORTBY to sort rows with the same priority, for example by name.
  • Wrap MATCH in IFERROR to send values that aren't in the list to the bottom.
  • In Excel 2019 or older, put the MATCH in a helper column and sort by it.
On this page+
  1. Why A to Z isn't enough
  2. The sort by custom list formula
  3. How the formula works
  4. Sort rows with the same priority
  5. Keep the list in cells or inside the formula
  6. What if a value isn't in the list?
  7. Sort a filtered list in a custom order
  8. Custom order in Excel 2019 and older
  9. Practise it

To sort by a custom list with a formula, give each row its position in your list with MATCH, then sort by those positions with SORTBY. This is how you put priorities in the order High, Medium, Low, or departments in the order your manager wants, instead of A to Z. The result is a live, sorted copy of your data that updates when the data changes.

Why A to Z isn't enough#

The SORT function orders text alphabetically, and alphabetical order is often wrong for business data. Sorting priorities A to Z gives High, Low, Medium. Sorting month names gives Apr, Aug, Dec. What you want is your own order, called a custom order.

The trick is to turn each value into a number that matches the order you want, then sort by the numbers. All the examples use this task list, with the custom order typed in E2:E4:

ABCDE
1TaskPriorityOwnerOrder
2Update budgetLowAnaHigh
3Fix login bugHighBenMedium
4Write reportMediumCaraLow
5Call supplierHighAna
6Plan offsiteLowBen
7Review contractMediumCara

The sort by custom list formula#

Use SORTBY with MATCH. Type this in an empty cell with room below and to the right, such as G2:

Excel formula
=SORTBY(A2:C7,MATCH(B2:B7,E2:E4,0))

The formula spills: it fills G2:I7 with the sorted table. A spill is a result that fills several cells from one formula. The High tasks come first (Fix login bug, Call supplier), then the Medium ones, then the Low ones.

SORTBY and MATCH-based sorting need Excel 2021 or Microsoft 365. The guide to SORT and SORTBY covers both functions in general.

How the formula works#

MATCH does the real work. With 0 as its last argument, it finds an exact match and returns its position in the list:

PriorityMATCH(…,E2:E4,0)
Low3
High1
Medium2
High1
Low3
Medium2

Because B2:B7 is a range, MATCH returns all six positions at once: {3;1;2;1;3;2}. SORTBY then sorts the rows of A2:C7 by those numbers, smallest first. Its syntax is:

Excel formula
=SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], ...)

The by_array must have the same number of rows as the data. Here both have six. In Microsoft 365 you can also use XMATCH(B2:B7,E2:E4), which defaults to an exact match.

Sort rows with the same priority#

Add a second pair to SORTBY to decide the order inside each group. This sorts by priority, then by task name A to Z:

Excel formula
=SORTBY(A2:C7,MATCH(B2:B7,E2:E4,0),1,A2:A7,1)

The result:

TaskPriorityOwner
Call supplierHighAna
Fix login bugHighBen
Review contractMediumCara
Write reportMediumCara
Plan offsiteLowBen
Update budgetLowAna

The 1 after each by_array means ascending. Use -1 to reverse a level: MATCH(B2:B7,E2:E4,0),-1 puts Low first. For more on sorting by several levels, see how to sort by multiple columns.

Keep the list in cells or inside the formula#

You can type the custom list straight into the formula as an array constant, a list in curly brackets:

Excel formula
=SORTBY(A2:C7,MATCH(B2:B7,{"High","Medium","Low"},0))

It returns the same result. A list in cells is usually better, because anyone can change the order without editing the formula. It also works for long lists, such as departments or month names (Jan to Dec).

What if a value isn't in the list?#

If a row holds a value that isn't in your list, such as "Urgent" or a typo like "Hihg", MATCH returns #N/A for it, and that error can break the whole sort. Wrap MATCH in IFERROR to give unknown values a large number, so they go to the bottom:

Excel formula
=SORTBY(A2:C7,IFERROR(MATCH(B2:B7,E2:E4,0),99))

Trailing spaces cause the same problem, because "High " doesn't match "High". Clean the column with TRIM if rows land at the bottom unexpectedly.

Sort a filtered list in a custom order#

To sort only some rows, FILTER them first, and filter the sort key the same way so both have the same number of rows. Ana's tasks in priority order:

Excel formula
=SORTBY(FILTER(A2:C7,C2:C7="Ana"),MATCH(FILTER(B2:B7,C2:C7="Ana"),E2:E4,0))

The result is Call supplier (High), then Update budget (Low). FILTER also needs Excel 2021 or Microsoft 365. The article on combining SORT and FILTER shows more patterns, and a unique sorted list shows how to add UNIQUE.

Custom order in Excel 2019 and older#

Without SORTBY, use a helper column, an extra column that holds a value only for sorting:

  1. In D2, type =MATCH(B2,$E$2:$E$4,0) and fill down (Windows: Ctrl+D; Mac: ⌘D). The $ signs keep the list fixed.
  2. Select the table and go to Data > Sort.
  3. Sort by the helper column, smallest to largest, and click OK.

In Microsoft 365 you can also keep the helper column and use SORT: =SORT(A2:D7,4) sorts by the 4th column. The SORT function guide explains its arguments. If you'd rather not use formulas at all, a custom list in the Sort dialog does the same job; the guide to custom sort in Excel shows how.

Practise it#

Sorting formulas click once you've watched one spill. Practise the SORT function in a live spreadsheet to sort by one and two columns, then try the modern Excel functions lesson for XMATCH and SORTBY. Each answer is checked instantly. Start with the High, Medium, Low exercise on this page.

Try it yourself

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

Sort the tasks by priority in the order listed in D2:D4 (High, Medium, Low). In F2, use SORTBY on A2:B7, sorting by MATCH(B2:B7,D2:D4,0).

fx
ABCDEFG
1
Task
Priority
Order
2
Update budget
Low
High
3
Fix login bug
High
Medium
4
Write report
Medium
Low
5
Call supplier
High
6
Plan offsite
Low
7
Review contract
Medium
8
9
10

Tip: SORTBY takes the data first, then what to sort by. MATCH(B2:B7,D2:D4,0) gives 1 for High, 2 for Medium and 3 for Low.

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.LessonModern Excel: XMATCH, SORTBY, TEXTSPLIT and spill references (A2#)Split names with TEXTSPLIT, find positions with XMATCH, sort by another column with SORTBY, and refer to a whole spilled result with A2#.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

How do I sort by a custom list using a formula in Excel?

+

Use =SORTBY(data,MATCH(column,list,0)). MATCH gives each row's position in your custom list, and SORTBY orders the rows by those positions. For example, =SORTBY(A2:C7,MATCH(B2:B7,E2:E4,0)).

Can the SORT function sort in a custom order?

+

Not on its own. SORT only sorts A to Z, Z to A or by size. Use SORTBY with MATCH instead, or add a helper column with the MATCH positions and sort by that column with SORT.

How do I sort High, Medium, Low in Excel?

+

Type High, Medium and Low in three cells in that order, then use =SORTBY(A2:C7,MATCH(B2:B7,E2:E4,0)), where B2:B7 holds the priorities and E2:E4 holds your list.

Can I put the custom list inside the formula?

+

Yes, as an array constant: =SORTBY(A2:C7,MATCH(B2:B7,{"High","Medium","Low"},0)). A list in cells is easier to change later, though.

How do I sort by a custom order in older Excel?

+

Add a helper column with =MATCH(B2,$E$2:$E$4,0), fill it down and sort the table by that column with Data > Sort. Or use a custom list in the Sort dialog.

Sources

  • SORTBY function - Microsoft Support
  • SORT function - Microsoft Support
  • MATCH function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 2, 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. Why A to Z isn't enough
  2. The sort by custom list formula
  3. How the formula works
  4. Sort rows with the same priority
  5. Keep the list in cells or inside the formula
  6. What if a value isn't in the list?
  7. Sort a filtered list in a custom order
  8. Custom order in Excel 2019 and older
  9. Practise it

Keep reading

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.

Data tools· 5 min read

Custom Sort in Excel: Sort by Your Own Order

To do a custom sort in Excel, go to Data > Sort, choose the column in Sort by, and set Order to Custom List. Type your order, such as High, Medium, Low, click Add and then OK. Excel sorts the rows in that order instead of alphabetically. With a formula, use =SORTBY(A2:C9,MATCH(B2:B9,E2:E4,0)), where E2:E4 holds the order.

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.

More on dynamic arrays

  • #SPILL! Error in Excel: What It Means and How to Fix It
  • The Spill Range Operator (#) in Excel
  • TAKE Function in Excel (and DROP): First or Last N Rows
  • Make a Top 5 List With SORT and FILTER
  • TRANSPOSE in Excel: Flip Rows and Columns
  • Get Unique Values From Multiple Columns in Excel
All dynamic arrays articles →

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