View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default CountIF by Background Color

If your color was set by conditional format, then Luke's function will not
work.


"Phil H" wrote in message
...
Luke,

I put this (corrected) function code in a new module 3 in personal.xls and
used the following cell formula: =COUNTYELLOW(A2:A6935), and get a #Name?
error in the cell.

"Luke M" wrote:

Correction, change this line:

Application.Volatile = True

to just

Application.Volatile

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Luke M" wrote:

You can use this short UDF called CountYellow. Note that it only counts
true
background color, not format generated by conditional formatting.
Detecting
conditional formatting is quite a bit more complicated...

Public Function CountYellow(r As Range) As Double
Application.Volatile = True

CountColor = 0
For Each c In r
If c.Interior.ColorIndex = 6 Then
CountColor = CountColor + 1
End If
Next

End Function
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Phil H" wrote:

Need a formula to count the cells in a range with a background color
yellow
(6).