How to Filter Multiple Columns by Color in Excel (2 Methods)

In this article, we will demonstrate how to filter multiple columns by color in Excel, and how to filter data by multiple colors too.

Suppose we have the below dataset containing several people’s names and the cities in which they reside in columns B and C.

2 Methods to Filter Multiple Columns by Color in Excel

We’ll apply different colors to this dataset based on the data type, and then filter the data by color using two methods.


Method 1 – Using the Filter Feature to Filter Multiple Columns by Color

In this method, we’ll filter multiple columns by color using Excel’s regular Filter option only. In our dataset, names start with the letters A, J, and M. We’ve highlighted the cells in column B with different colors according to the first letter of the name. For instance, all the names starting with A are in green. Then we’ve highlighted duplicate cities in similar colors. For example, the city Phoenix is present twice, so both of the cells are blue.

Now we’ll filter column B by the color green, and column C by blue.

Use Excel Filter Feature to Filter Multiple Columns by Color

Steps:

  • Select any cell in the dataset, then from the Ribbon go to Data > Filter. Or use Ctrl + Shift + L to apply the Filter.

Use Excel Filter Feature to Filter Multiple Columns by Color

As a result, the drop-down arrow for the filter appears next to our Header cells..

Use Excel Filter Feature to Filter Multiple Columns by Color

  • Click on the dropdown arrow for column B, select Filter by Color, and choose green from Filter by Cell Color (as in the screenshot below).

Use Excel Filter Feature to Filter Multiple Columns by Color

Column B is filtered by the color green.

Use Excel Filter Feature to Filter Multiple Columns by Color

Now we’ll filter column C by another color.

  • Select the drop-down arrow, click on Filter by Color, and choose the color blue.

Column C is filtered by the color blue. So, we have successfully filtered multiple columns by color.


Method 2 – Using Excel VBA to Filter Multiple Columns by Color

Now we’ll use a simple VBA code to create a User Defined function to find the color index for each color applied to the cells of columns B and C. Then we’ll filter column B for names starting with J (in the peach color) and column C for the city Portland (light orange color).

Steps:

  • Add two helper columns to the original dataset as follows:

Filter Multiple Columns by Color Using Excel VBA

  • To create a UDF, go to Developer > Visual Basic to open the VBA window (or press Alt + F11).

Filter Multiple Columns by Color Using Excel VBA

  • In the VBA window, right-click on the VBAProject and go to Insert > Module.

Filter Multiple Columns by Color Using Excel VBA

  • Enter the following code in the Module:
Function FindColor(n As Range) As Integer
FindColor = n.Interior.ColorIndex
End Function

Filter Multiple Columns by Color Using Excel VBA

  • Go to the worksheet where the newly created function will be applied.
  • Enter the below formula in Cell D5, and press Enter:
=FindColor(B5)

Filter Multiple Columns by Color Using Excel VBA

The color index of Cell B5 is returned.

  • Use the Fill Handle (+) tool to get the color index for the rest of the colored cells in column B.

  • Similarly, use the same function to get the color index of the cities in column C.

  • Apply the Filter to the dataset by pressing Ctrl + Shift + L.
  • Click on the filter drop-down arrow of column D and add a checkmark only for the color index 19.
  • Click OK.

Filter Multiple Columns by Color Using Excel VBA

The below output is returned. As we have filtered column C only for peach color (index: 19), column B is also filtered for the same color, which applies to names starting with the letter J.

Filter Multiple Columns by Color Using Excel VBA

  • Similarly, filter column E for color index 36.

When column E is filtered for color index 36, column C is filtered for the light orange color which applies to the city of Portland.

So, we have successfully filtered multiple columns (columns B and C) by color.


How to Filter Data by Multiple Colors in Excel

Usually in Excel we filter data by one color only, but we can filter rows or a column by multiple colors too with a VBA UDF. Suppose we have highlighted the rows of the below dataset in different colors. Now we will filter the rows by the colors green and blue.

Filter Data by Multiple Colors in Excel

Steps:

First, create the VBA UDF to find the color index.

  • Press Alt + F11 to bring up the VBA window.
  • Insert a Module from VBAProject as in Method 2.
  • In the new Module, enter the same VBA code used in Method 2.
  • Insert a helper column next to the original data.
  • Enter the below formula in Cell D5 and press Enter:
=FindColor(B5)

Filter Data by Multiple Colors in Excel

The color indices for all colors present in the rows below are returned.

Filter Data by Multiple Colors in Excel

  • Apply the Filter to the dataset.
  • Click on the drop-down icon of column D, and place a checkmark only on the indices 15 and 24.
  • Click OK.

The dataset is filtered for rows colored in blue and green.

Filter Data by Multiple Colors in Excel

We have successfully filtered rows by multiple colors (blue and green) at the same time.


Download Practice Workbook


<< Go Back to Color Filter | Filter in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Hosne Ara
Hosne Ara

Hosne Ara is a materials and metallurgical engineer who loves exploring Excel and VBA programming. To her, programming is like a time-saving superhero for dealing with data, files, and the internet. She's skilled in Rhino3D, Maxsurf C++, MS Office, AutoCAD, and Excel & VBA, going beyond the basics. With a B. Sc. in Materials and Metallurgical Engineering from Bangladesh University of Engineering and Technology, she's shifted gears and now works as a content developer. In this role, she... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo