Count number of cells in a cell range that has a particular color

myletterboxnp

New Member
Joined
May 20, 2022
Messages
28
Office Version
  1. 365
Hi all,

A2:A20 cells have different colors such as red, green and yellow.

In A22, what should be the formula to count the number of the red cells in the range A2:A20
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Are the cells being colored manually, or by Conditional Formatting Rules?

If they are being colored by Conditional Formatting Rules, you may be able to use the same rules you use to set up the Conditional Formatting Rules in a COUNTIF or COUNTIFS function to count them.

If they are being colored manually, there are of ways to count them.
See this: 6 Ways to Count Colored Cells in Microsoft Excel [Illustrated Guide] | How To Excel
 
Upvote 0
This are manual formatting. I looked at that link earlier and did not understand properly. I just need a simple formula if there is.
 
Upvote 0
This are manual formatting. I looked at that link earlier and did not understand properly. I just need a simple formula if there is.
There is no "simple" native Excel formula, which is why you have to use one of those options.
That is because native Excel formulas only run against formula values, not cell formatting.

Personally, I like the VBA option, because all you have to do is copy/paste the code into the VB Editor to create your own User Defined Function to do this.
Then you can use the function on your spreadsheet, like any other Excel function.
So it doesn't involve much VBA knowledge (the code has already been written for you!), and you can easily use it like any other Excel function.
 
Upvote 0
hi there,

I tried using VBA option but got stuck. For example, I pressed Alt F11 and it showed me a VBA project screen. Now where do I paste the copied codes? Sorry for asking all these small questions.

Kind Regards
 
Upvote 0
Thanks, so I added to codes (module1) and saved the file also as macro enabled workbook. When I opened the workbook and pressed Alt F8 to run the macro, there's no macro name to choose. What am I doing wrong?

Kind Regards,
 
Upvote 0
Note that if you copy/pasted a FUNCTION, it will not show up in the list of Macros! Functions and Macros (Procedures) are different thing.
If you are using a Function, you just use it like you would any other Excel function (like "SUM", "LEFT", etc).
 
Upvote 0
Sorry its to complicated for me. I give up. Thanks though!
Its actually probably not quite as complicated as you think. Let me walk you through it.

If you copied the Function code from the link to a new Module (like it sounds you already did):
VBA Code:
Function COLORCOUNT(CountRange As Range, FillCell As Range)
Dim FillColor As Integer
Dim Count As Integer
FillColor = FillCell.Interior.ColorIndex
For Each c In CountRange
    If c.Interior.ColorIndex = FillColor Then
        Count = Count + 1
    End If
Next c
COLORCOUNT = Count
End Function

and then you wanted to count the number of red cells in the range A1:A10 (see image below):

1667843727268.png


you could do that with the following formula in cell D1 and copy down to D3:
Excel Formula:
=colorcount(A$1:A$10,C1)

Note that the formula has two arguments.
The first is the range you want to count (A$1:A$10)
The second is a cell with the color that you to count (C1)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top