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

We have attached a sample workbook containing sales information, including Date, Product, Country, Quantity, and Sales.

Count cells with specific color in excel


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


Method 1 – Using Filters and the SUBTOTAL Function to Count Colored Cells

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

  • Click on the result cell and type =SUBOTAL( and select 2-COUNT.

  • Use 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.
  • We will filter the data table by color.

  • Here’s the result for yellow.

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

Count cells with specific color

  • Whenever you update your data, you need to repeat the process.

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

Steps:

  • Go to Formulas and select Define Name. A dialog box will pop up.

Count cells with specific color using get.cell

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

  • Click on cell G5 and insert =GetSpecificColor (the formula you named in the previous step), then press Enter.

Count cells with specific color using macro

  • Here’s the result, a color code of the reference cell.

  • Drag down to AutoFill rest of the series.

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

  • Hit Enter.

  • 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

Steps:

  • Right-click on the sheet name and go to View Code.

Count cells with specific color using vba

  • Copy and paste the VBA code below into the module.
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

  • Press F5 or the play button to run the code.
  • Click on J5 and use the following formula.
=MyColorCount($B$5:$B$13,H5)

Count cells with specific color vba

  • Press Enter.

  • Drag down to AutoFill.


Method 4 – Find and Select to Count Colored Cells

Steps:

  • Go to Find and Select from the Home tab and click Find.

Count cells with specific color using Find and replace

  • A dialog box will pop up. Select Choose Format From Cell….

  • Select any cell with color in it and click Find All.


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


Practice Section

We’ve attached a practice workbook where you can practice these methods.

Count cells with specific color in excel


Download the Practice Workbook


<< 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

2 Comments
  1. Hello,

    I am trying to understand “get function”.
    Where does “38” come from, what should i replace it with?
    I would be appreciated if you can help me.

    Sincerely,
    Selinay

    • Hello Selinay,

      The GET.CELL function retrieves specific information about a cell. In this case, 38 is the code for the background color index of the cell. The formula returns the color index of cell B5 in the ‘Get Cell’ sheet.

      The “38” is a code used in the GET.CELL function to retrieve the color index of a cell. It identifies the background color.
      If the you want to get different information, such as font color or cell format, you can replace “38” with the appropriate code.

      Here is a list of some GET.CELL function codes:

      38: Returns the background color of the cell.
      24: Returns the font color.
      63: Returns if the cell contains a formula (TRUE/FALSE).
      17: Returns the number format of the cell.
      50: Returns the width of the cell.
      64: Returns if the cell is locked (TRUE/FALSE).

      These codes help retrieve specific cell information.

      GET.CELL is a legacy Excel function, which needs to be used within named ranges to work properly in modern versions of Excel.

      Regards
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo