Counting coloured cells

A

amvena

I have a list of percentages that are conditionally formatted and I want to
be able to count how many cells are each different colour. I don't think you
can do this with count if as it only looks for numbers or text and not
formatting but essentially I want to count the number of cells in a range
which are red/gold or green.
 
M

Mangesh Yadav

Use the following UDF


Function CountColor(rng As Range, colorRng As Range)

For Each cl In rng
If cl.Interior.ColorIndex = colorRng.Interior.ColorIndex Then ' use
this for background color
CountColor = CountColor + 1
End If
Next

End Function


Usage
=countcolor(A1:A10,A1)

A1:A10 is the range for which you want to count, and A1 is the cell which
has the desired color format which you want as criteria


Mangesh
 
B

Bob Phillips

This won't work for conditionally formatted cells. For that you need to test
whether it meets the CF condition.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Top