Codementor Events

How to Count Colored or Highlighted Cells in Excel

Published Apr 04, 2019
How to Count Colored or Highlighted Cells in Excel

The COUNT function in Excel counts cells containing numbers in Excel. You cannot count colored or highlighted cells with the COUNT function. But you can follow a few workarounds to count colored cells in Excel. In this tutorial, you will learn how to count colored cells in Excel.

In excel, you can count highlighted cells using the following workarounds:

1-Applying SUBTOTAL and filtering the data
2-Using the COUNT and GET.CELL function
3-Using VBAStart writing here...

Using VBA
You can also create a custom function with VBA to count highlighted cells in Excel. To do that you need to create a custom function using VBA that works like a COUNTIF function and returns the number of cells for the same color.

You will follow the syntax: =CountFunction(CountColor, CountRange) and use it like other regular functions.Here CountColor is the color for which you want to count the cells. CountRange is the range in which you want to count the cells with the specified background color.

To count the cells highlighted in red, follow the steps below:

Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
Click Insert > Module.

Paste the code in the image into the Module Window.
=ColorCount(A2, C2:C10).
In this code, you are defining a function with two arguments rColor and rRange. You are going to save the value of the background color of A2 in lCol. Then you are going to run a FOR loop where, if the cell’s background color matches the color in lCol, you increment vResult. This function returns the value of vResult, which is the count of the cells having the same background color.

Discover and read more posts from Ahmed
get started
post commentsBe the first to share your opinion
Show more replies