View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Counting a colour that is Conditionally Formatted

Conditional formatting doesn't return a value you can check on directly.
See Chip Pearson's site for an explanation and code:

http://www.cpearson.com/excel/CFColors.htm

--
Regards,
Tom Ogilvy

Crash wrote in message
...
I have a grid that conditionally formats the background colour to Green,
Red or White depending on a criteria. I want to count the number of
times green appears in a row. I've tried modifying the CountByColor
Function but to no avail.

Is this possible?

TIA

Jon

Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Font.ColorIndex = ColorIndex Then TempCount = TempCount +
1
Next cl
Set cl = Nothing
CountByColor = TempCount
End Function