View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy Patrick Molloy is offline
external usenet poster
 
Posts: 1,049
Default How do I calculate number of colored cells?

you can use a udf for this:

Sub test_colorcount()
MsgBox colorcount(Range("I2"), Range("H6:J15"))
End Sub

Function colorcount(base As Range, target As Range) As Long
Dim cell As Range
Dim count As Long
For Each cell In target.Cells
If cell.Interior.Color = base.Interior.Color Then count = count + 1
Next
colorcount = count
End Function

color cell I1 (for my example) say yellow. Put a border arounf H6:J15 so you
can see it clearly, then color a few cell with the same fill as I2. in
another cell put

=colorcount(I2,H6:J15)







"Rui" wrote in message
...
Hi to master gurus in excel,

I really need your help to solve one issue: how to calculate number of
collor cells?

For instance, from cells range A2:F2 (6 cells),if there are 2 cells filled
in any colors, the counter in cell G2 should be equal to 4(6-2).

Any thoughts?
--
Thanks in advance!