How to Sort Custom Department Lists in Excel Using the MATCH Function

📅 Aug 06, 2026 📝 Sarah Miller

Sorting organizational data often proves frustrating when standard alphabetical sorting disrupts your company's actual operational hierarchy. While traditional ascending filters work well for basic datasets, they fail to accommodate custom corporate structures. By leveraging Excel's MATCH function, you gain the power to dynamically sequence department data according to your specific chart. Note the core stipulation: this method requires a predefined master reference array to map the custom ranks. For example, you can seamlessly order departments as "Executive," "HR," then "Finance." Below, we outline the exact formula steps to implement this advanced sorting technique.

How to Sort Custom Department Lists in Excel Using the MATCH Function

Excel Formula To Sort Custom Department Lists With Match Function

When working with organizational data in Excel, sorting alphabetically is often the first instinct. However, alphabetical sorting rarely aligns with business logic. For instance, sorting a department list alphabetically puts "Accounting" before "Executive Suite" and "Warehouse" at the very bottom, completely ignoring the operational hierarchy of your company.

To present reports that make sense to stakeholders, you need a custom sort order. While Excel has a built-in "Custom List" feature in its Sort dialog, it is static, manual, and does not update dynamically when your data changes. The most robust, professional way to handle custom sorting is by using Excel formulas-specifically leveraging the power of the MATCH function.

In this guide, we will explore how to build a dynamic, formula-based custom sorting system using the MATCH function, covering both legacy helper-column methods and modern dynamic array formulas like SORTBY.

Why the MATCH Function is Key to Custom Sorting

The secret to custom sorting lies in translating text values (like department names) into numeric ranks. Once each department has a numeric rank based on your preferred order, Excel can easily sort those numbers from lowest to highest.

The MATCH function is perfect for this task. Its syntax is:

=MATCH(lookup_value, lookup_array, [match_type])
  • lookup_value: The department name in your data table that you want to rank.
  • lookup_array: A separate, master list containing your departments in the exact custom order you want them sorted.
  • match_type: Set to 0 for an exact match.

By using MATCH, Excel looks up the department from your data table in your custom master list and returns its relative position as a number. If "Executive" is first in your master list, MATCH returns 1. If "Sales" is fifth, it returns 5. This simple mechanism forms the backbone of custom formula sorting.

Method 1: The Helper Column Approach (Compatible with All Excel Versions)

If you are using older versions of Excel (such as Excel 2013, 2016, or 2019), or if you want to keep your data in a standard, scrollable table format, the helper column approach is the most reliable method.

Step 1: Set Up Your Custom Master List

First, create your custom department hierarchy somewhere in your workbook. It is best practice to place this on a separate reference sheet or to the side of your main table. Let's assume you place your master list in cells E2:E6:

Cell Master Department Order
E2 Executive
E3 Finance
E4 HR
E5 IT
E6 Operations

Step 2: Add the MATCH Formula to Your Data Table

Now, go to your main data table. Assume your department column is Column B, starting at row 2. Insert a new column next to your data and label it "Sort Order". In cell C2, enter the following formula:

=MATCH(B2, $E$2:$E$6, 0)

Note: It is crucial to use absolute references (dollar signs $) for the master list range ($E$2:$E$6) so that the range remains locked when you copy the formula down the column.

Drag this formula down to apply it to all rows in your data set. You will notice that each row now displays a number corresponding to its department's priority in your master list.

Step 3: Sort Your Table

To sort your entire dataset based on your custom order:

  1. Click any cell inside your data table.
  2. Go to the Data tab on the Ribbon.
  3. Click the Sort button.
  4. In the Sort dialog box, select "Sort Order" (your helper column) under Column, choose "Cell Values" under Sort On, and select "Smallest to Largest" under Order.
  5. Click OK.

Your table is now sorted perfectly according to your custom department hierarchy!

Method 2: Dynamic Sorting with SORTBY and MATCH (Excel 365 & 2021)

If you are using modern Excel (Microsoft 365 or Excel 2021), you can bypass helper columns and manual sorting dialogs entirely. By combining the SORTBY dynamic array function with MATCH, you can create a fully automated, self-sorting list.

The Formula Syntax

Assume your unsorted source data is in the range A2:B10, where Column A contains Employee Names and Column B contains Departments. Your custom master list of departments is located in E2:E6.

In an empty cell where you want your sorted results to appear, enter the following formula:

=SORTBY(A2:B10, MATCH(B2:B10, E2:E6, 0), 1)

How It Works

This powerful formula works from the inside out:

  • MATCH(B2:B10, E2:E6, 0): This evaluates the entire department column (B2:B10) against your custom list (E2:E6). Because we passed an array to the lookup value, it returns an array of numbers representing the rank of each row's department.
  • SORTBY(A2:B10, ..., 1): The SORTBY function takes your original data range (A2:B10) and sorts it based on the array of numbers generated by the MATCH function. The 1 at the end tells Excel to sort in ascending order (1 to 5).

Because this is a dynamic array formula, it automatically "spills" the sorted results into adjacent cells. If you add or change departments in your source data, the sorted output updates instantly without requiring manual sorting.

Handling Missing Values with IFERROR

A common issue with formula-based sorting occurs when your source data contains a department that is not listed in your custom master list. If this happens, the MATCH function will return an annoying #N/A error, which will break your entire sorting sequence.

To prevent this, wrap your MATCH function in an IFERROR function. This allows you to assign a default high rank (like 999) to any unlisted departments, automatically pushing them to the bottom of your sorted list.

Using IFERROR in Helper Columns

=IFERROR(MATCH(B2, $E$2:$E$6, 0), 999)

Using IFERROR with SORTBY

=SORTBY(A2:B10, IFERROR(MATCH(B2:B10, E2:E6, 0), 999), 1)

Now, if someone enters "R&D" in your data table, but "R&D" is missing from your master list, the formula will assign it a value of 999. It will safely sort to the bottom of the list rather than crashing your formula.

Visualizing the Setup

Here is a visual representation of how the data flows from raw input, through the formula, and into the final custom-sorted output using the SORTBY approach:

Source Employee (A) Source Dept (B) Custom Order (E) Sorted Employee Sorted Dept
John Doe Operations Executive (Rank 1) Sarah Jenkins Executive
Jane Smith Finance Finance (Rank 2) Jane Smith Finance
Sarah Jenkins Executive HR (Rank 3) Mike Ross HR
Mike Ross HR IT (Rank 4) John Doe Operations

Pro-Tip: Use Excel Tables for Dynamic Master Lists

To make your custom sorting system incredibly resilient, convert both your source data and your master list into official Excel Tables (select your data and press Ctrl + T).

Using tables enables structured references, meaning your formulas will automatically adjust as you add or remove departments from your custom hierarchy list. For example, if your master list is formatted as a table named DeptList with a column named Department, your formula becomes self-documenting and dynamic:

=SORTBY(A2:B10, MATCH(B2:B10, DeptList[Department], 0), 1)

Conclusion

Mastering custom sorting with the MATCH function elevates your Excel skills from simple data entry to professional reporting. Whether you choose the reliable helper-column method for backward compatibility, or harness the speed of SORTBY in modern Excel, assigning numeric ranks to your departments ensures your data is always structured logically, dynamically, and accurately.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.