Excel Formula to Count Cells with Specific Color (4 Ways)

Coloring cells is a popular method to visualize data in an Excel worksheet. Sadly, there is no in-built function in Excel to do it. We’re going to show you some simple methods using Excel formula to count cells with a specific color. We have attached a sample workbook containing Date, Product, Country, Quantity, and Sales for your better understanding.

Count cells with specific color in excel


How to Count Cells with Specific Color Using Excel Formula: 4 Easy Ways

Our four methods include Excel commands, functions, and a VBA code.


Method 1: Filters and the SUBTOTAL Function to Count Colored Cells

We can also use the filter option to count specific cells with color in Excel. We will see the use of the SUBTOTAL formula here. Let’s jump into the method.

Steps:

  • Select the entire range and go to the Data tab then select Filter or press CTRL+SHIFT+L.

Count cells with specific color using Filter

  • After that, click on cell and type =SUBOTAL( and select 2-COUNT.

  • Now, type the following formula.
=SUBTOTAL(2,F5:F13)

  • Press the ENTER key.

Count cells with specific color using subtotal

This will return the number of rows which is 9 in this data.

  • Now, we will filter the data table with color, follow the process shown in the image below.

  • After, clicking OK we will get our result like the following.

If we selected green in the filter option, the process will return the result like this.

Count cells with specific color

This is easy and simple, but whenever you update your data, you need to repeat the process.


Method 2: Excel Formula to Count Cells with Specific Color Using GET.CELL Function

Although Excel has a method, to obtain the fill color of a cell, it is a Macro 4 function from the legacy.

Steps:

  • First, go to the Formulas and select Define Name. A dialogue box will pop up.

Count cells with specific color using get.cell

  • Now, type your function Name and type the following formula in the Refers to and click OK.
=GET.CELL(38,'Get Cell'!$B5)

  • Now, click on cell G5 and type =GetSpecificColor, and press ENTER key.

Count cells with specific color using macro

After pressing ENTER we will get.

  • Now, drag down to AutoFill rest of the series.

It is visible that only the colored cell is defined as a unique number. No filled cells are given zero. We will use COUNTIF to count cell numbers now.

  • Now, type the following formula in cell J5.
=COUNTIF($G$5:$G$13,36)

  • Now, press the ENTER key.

If we drag down to AutoFill, we will get the result as follows.


Method 3: Excel Formula to Count Cells with Specific Color Using VBA

Finally, in this article, we will see the VBA method to count specific cells with color.

Steps:

  • First, right-click on the sheet and go to View Code.

Count cells with specific color using vba

  • After that, copy and paste the VBA code below.
Function MyColorCount(CountRange As Range, CountColor As Range)

Dim CountColorCells As Integer
Dim TotalColorCount As Integer

CountColorCells = CountColor.Interior.ColorIndex
Set rCell = CountRange
For Each rCell In CountRange
If rCell.Interior.ColorIndex = CountColorCells Then
TotalColorCount = TotalColorCount + 1

End If

Next rCell

MyColorCount = TotalColorCount
End Function

  • After that, press the F5 or play button to run the code.
  • Now, click on J5 and type the following formula.
=MyColorCount($B$5:$B$13,H5)

Count cells with specific color vba

  • Press ENTER key.

  • Now, drag down to AutoFill.

Through this code, we are creating a user function MyColorCount which will identify only the colored cell, and using COUNTIF we are calculating the total colored cell number.


Method 4: Find and Select Command to Count Colored Cells

In this section, we will see how to count color cells using the Find and Select command in Excel. Though it’s not any conventional formula, still we’re mentioning it for your ease of experience.

Steps:

  • First, go to Find and Select from the Home Tab and click Find.

Count cells with specific color using Find and replace

  • After that, a dialogue box will pop up and we will select, Choose Format From Cell….

This will allow us to select colored cells .and select any cell with color in it and click Find All.


As a result, we will get the total number of colored cells and their location in the worksheet, as shown in the following image.

Count cells with specific color using Find

This is a simple method. But we have to repeat the process every time for a different color.


Practice Section

The single most crucial aspect in becoming accustomed to these quick approaches is practice. As a result, I’ve attached a practice workbook where you may practice these methods.

Count cells with specific color in excel


Download Practice Workbook


Conclusion

These are 4 different Excel formula to count cells with a specific color. Based on your preferences, you may choose the best alternative. Please leave them in the comments area if you have any questions or feedback.


<< Go Back to Colored Cells | Count Cells | Formula List | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mahbubur Rahman
Mahbubur Rahman

MAHBUBUR RAHMAN is a leather engineer with a talent for Excel and a passion for VBA programming. To him, programming is like a time-saving wizard, making data manipulation, file handling, and internet interactions a breeze. His skill set extends to SPSS, STATA, Deep Neural Networks, and Machine Learning. Holding a B.Sc in Leather Engineering from Khulna University of Engineering & Technology, he's shifted to become a content developer. In this role, he crafts technical content centred around Excel... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo