Count Cells By Color In Excel

Publication Date :

Blog Author :

Table Of Contents

arrow

What Is Count Cells By Color In Excel?

Count cells in Excel enables users to count the number of cells based on color. Though there is no inbuilt option to count the number of colored cells in Excel, there are a number of methods we can use to count cells by color.

For example, consider the below table showing temperatures in 3 different countries. Now, assume that we have to count the cells which are green in color.

Count number of cells in Excel Intro Example

Step 1: Press the shortcut keys, Ctrl + F. The Find and Replace window appears. Press on the Options>> button.

The window will display more options. Click on the Format option.

Step 2: The window, Find Format appears. Select Choose Format from Cell… option.

Next, using the eye dropper tool, select the desired color. In this example, it is green.

As soon as we select the color, we can see the Preview option highlighting the same color.

Press Find All. The result will be displayed as highlighted in the below image.

Count number of cells in Excel Intro Example - Output.jpg

Likewise, we can count number of colored cells in Excel.

  • Count number of colored cells is possible in Excel and there are many methods to count colored cells in Excel.
  • Though we do not have any built-in function in Excel, we can easily count the colored cells using the following methods
    • The Auto Filter option
    • The VBA code
    • The FIND method
    • The filter method with a subtotal function
  • The FIND method is one of the easiest and simple methods to count the number of coloured cells in Excel.

How To Count Cells With Color In Excel?

There are multiple ways we can use to count cells based on the color of the cell in Excel.

  1. Method #1 – Count cells with color using the filter method with a subtotal function.
  2. Method #2 – Count cells with color by creating a function using VBA code.

Examples

Now, let us discuss each of the methods in detail, along with an example –

#1 - Using Filter Method With Sub Total Function

As we said, we have multiple methods to count cells based on the color of the cell in Excel. This method uses the filter and subtotal function.

The steps to use the filter method with the subtotal function in Excel are as follows.

  1. First, we need to apply a subtotal function, so open the SUBTOTAL function in Excel at the end of the data.


    How to Count Cells with Color in Excel Example 1.1

  2. Once we open the SUBTOTAL function, we are supplied with a function list under this; since we are counting cells, choose the 2 – COUNT function.


    How to Count Cells with Color in Excel Example 1.2

  3. After selecting the subtotal method next, we need to choose a range of cells to be counted.


    How to Count Cells with Color in Excel Example 1.3

  4. Now the count of these cells will be 7.


    How to Count Cells with Color in Excel Example 1.4

  5. For the above data, the structure applies a filter option.


    How to Count Cells with Color in Excel Example 1.5

  6. We must click on the drop-down list of filters to go to “Filter by Color.” It will show up all the available colors to filter.


    How to Count Cells with Color in Excel Example 1.6

  7. We must choose any color. As a result, we will have those colored rows.


    How to Count Cells with Color in Excel Example 1.7

  8. As we can see above, our SUBTOTAL function shows the count of the filtered rows only. So, for example, since there are only two rows marked with orange color, the SUBTOTAL function shows the count as three only. Similarly, choose another color and see whether it works perfectly or not.


    How to Count Cells with Color in Excel Example 1.8

This count is 2, so we have an updated result.

#2 - Create Function Using VBA Coding

Unfortunately, as we told you, we do not have any built-in function which can help us count cells based on color in Excel. Again, we have been told there is no built-in function, but the beauty is we can create our function by using VBA coding.

Below is the code we have already written to create a function to count cells based on color.

Code:

Function ColorCount(ColorCell As Range, DataRange As Range)

   Dim Data_Range As Range
   Dim Cell_Color As Long

   Cell_Color = ColorCell.Interior.ColorIndex

   For Each Data_Range In DataRange

   If Data_Range.Interior.ColorIndex = Cell_Color Then
   ColorCount = ColorCount + 1
   End If

   Next Data_Range

End Function
Example 1.9

As shown below, we have to copy the above code and paste it into our VBA module.

How to Count Cells with Color in Excel Example 1.10

Now come back to the worksheet where we have data and create three cells with color.

Example 1.11

We must put an equal sign and open the function we have created using the above code.

How to Count Cells with Color in Excel Example 1.12

The first argument with this function is “we need to select the color cell that we need to count,” so in this case, we will choose the E2 cell.

Example 1.13

The second argument is the range of cells, we need to count the selected cell color.

How to Count Cells with Color in Excel Example 1.14

That is all we need for this function. Next, close the bracket and press the “Enter” key to get the count of the selected cell color.

Example 1.15

Similarly, we need to do it for other colored cells. Again, we get the following result.

How to Count Cells with Color in Excel Example 1.16

It is done by using the VBA “User Defined Function,” which will loop through a provided range of cells and count the number of cells that exactly hold the same color as the provided cell color.

Then it will sum all the matched color cells and return the result as a count of that color cell.

Example 1.17

Like this, we can count cells with colors in Excel. There are other methods, but those are slightly complicated, so we must go for the easy one at the start of the learning.

Important Things To Note

  • The SUBTOTAL function counts cells only, which are visible, so as the filter is applied, it will count only those filtered colored cells.
  • VBA code is for the UDF function because there are no built-in functions, so we have to create our own.

Frequently Asked Questions

1. Is there an in-built option to count colored cells in Excel?

There is no built-in function to count colored cells in Excel. But, we can use the below-mentioned different methods to count colored cells in Excel.
They are:
Count colored cells by using the Auto Filter option
Count colored cells by using the VBA code
Count colored cells by using the FIND method

2. How to calculate colored cells in Excel?

We can easily calculate colored cells using the FIND method. For example, consider the below table showing the rating of various products in columns A and B, respectively.

Count number of cells in Excel FAQ 2

Assume that we have to count the rows which are green in color.
The steps are:

Step 1: Press the shortcut keys, Ctrl + F. The Find and Replace window appears. Press on the Options>> button.

The window will display more options. Click on the Format option.

Step 2: The window, Find Format appears. Select Choose Format from Cell… option.

Next, using the eye dropper tool, select the desired color. In this example, it is green.

As soon as we select the color, we can see the Preview option highlighting the same color.

Press Find All. The result will be displayed as highlighted in the below image.

Count number of cells in Excel FAQ 2 - Output

Likewise, we can count the number of colored cells in Excel.

3. Can we use the COUNTIF function to count number of colored cells in Excel?

Yes. We can use the COUNTIF function to count colored cells in Excel.
The syntax of COUNTIF function is =COUNTIF(range, criteria)