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.
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.
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])
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.
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.
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 |
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.
To sort your entire dataset based on your custom order:
Your table is now sorted perfectly according to your custom department hierarchy!
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.
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)
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.
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.
=IFERROR(MATCH(B2, $E$2:$E$6, 0), 999)
=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.
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 |
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)
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.