PDA

View Full Version : Solved: count the cells with fill color



Dipwad
11-27-2007, 07:54 PM
OK I have a range of cells that contain numbers. Some of these cells are also highlighted by using fill color. My question.....is there a formula that will count these highlighted cells within a range? I have tried using countif but don't know the correct criteria or even if it is possible.
One thing I do know is that if it is possible....someone here knows how!

TIA
Dipwad

anandbohra
11-27-2007, 10:53 PM
here is the code (Not Mine)

Function CountColor(ColoredRange As range, CountRange As range)
Application.Volatile
Dim rCell As range
Dim ColorInterior As Integer
Dim cOccurance

ColorInterior = ColoredRange.Interior.ColorIndex
For Each rCell In CountRange
If rCell.Interior.ColorIndex = ColorInterior Then
cOccurance = cOccurance + 1
End If
Next rCell
CountColor = cOccurance
End Function

Bob Phillips
11-28-2007, 12:52 AM
See http://www.xldynamic.com/source/xld.ColourCounter.html for a working solution

Dipwad
11-28-2007, 07:07 AM
Thanks guys! I finally figured out a solution with the help of the link xld provided above.
I used this formula with some modification: =SUMPRODUCT(--(ColorIndex(A1:A100)=3)) Instead of colorindex (my excel 2003 didn't reconize this word) I used intcolor. The intcolor function comes from the addin that is provided in the top sticky in this forum. I would post the link but my minimal post count will not allow me.
Thanks again for your help.