Return to Excel Formulas List

Custom Sort List with Formula – Excel & Google Sheets

Download Example Workbook

Download the example workbook

This tutorial will demonstrate how to dynamically sort data by a custom sort order in Excel and Google Sheets.

custom sort list Main Function

SORTBY Function in Excel 365

The SORTBY Function produces a dynamic array of sorted data.

In this example, we use the SORTBY Function to take a data table and produce a dynamic array that sorts it by Team following a Custom Sort List:

SORTBY Custom Sort List

Note: The SORTBY Function is written in only cell H3. The rest of the table will populate automatically.

The sorted table is dynamic, which means that if any of the Team or Player Name values change or records or added / deleted, then the output table will automatically re-size and re-sort.

Note: The SORTBY Function is not available in Excel 2019 or earlier. Read below for sorting options available for earlier versions of Excel.

To explain how this formula works, let’s break it down into steps:

Our final formula is:

First, we define the data table that needs to be sorted. This will be B3:D8.

Next, we need to define the sort order. We will use the MATCH Function to find the order in which each Team name appears in the Custom Sort List. This part of the formula is:

Adding in the values from the cell ranges, we get:

The MATCH Function replaces all Team names with the order in which they appear in the Custom Sort List, using an exact text match:

This array of values is then used as the sort order by the main SORTBY Function:

The sorted table is then produced

Custom Sort List – Pre-Excel 365

As the SORTBY Function is not available to Excel users before the Excel 365 version, we will now show how to perform the same task using a more manual process.

The built-in Excel sort tool can be used to sort by a Custom Sort List by selecting the ‘Custom List…’  from the sort order options in the sort tool:

CustomSortList Pre356 Raw

A new Custom List should be added as a comma separated list. In this example, we add: ‘Yellow, Blue, Red’

Custom List

The Custom List is then shown in the sort order selection

Custom List 2

The data table is then sorted by the Custom List values

Custom List 3

Note that this custom sort order is saved within the workbook and is available to be used again. If you do not wish to add a Custom List to Excel, then a method using a helper column can be tried instead.

Custom Sort List With Helper Column – Pre-Excel 365

In this next, example, we use the MATCH Function in a helper column to define a Custom Sort Order by referencing a Custom Sort List:

CustomSortList Pre356 (before)

Note the use of the $ symbol when referencing the Custom Sort list. Please read our article on Locking Cell References to learn more on this subject.

One the helper column has been added, a manual sort process can be run using the Sort Wizard:

SORT

SORT 1

This then produces the table sorted following the Custom Sort Order:

SORT 2

If any changes are made to the Team or Custom Sort List values, then the sort wizard will need to be re-run to update the sort order of the data table.

Custom Sort List with Formula in Google Sheets

The SORTBY Function is not available in Google Sheets, but its SORT Function can be used instead and is more powerful than the SORT Function in Excel 365. It allows us to use custom sort lists to dynamically sort data ranges.

In this example, we use the Google Sheets SORT Function to take a data table and produce a dynamic array that sorts Team values by a Custom Sort List:

custom sort list Google Function

The Google Sheets SORT Function sorts data by the specified column numbers or custom sort orders in the input data and allows us to set whether the sort order is ascending or not