Counting a colour that is Conditionally Formatted

C

Crash

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
 
A

Auric__

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

How about a Select Case that looks at the formula or the value? If it
can be expressed as an Excel formula, it can be expressed in VBA code.
 
R

Ron Rosenfeld

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

I do not believe so. You would need your code to check for the *condition*
that produces the Green result.


--ron
 
C

Crash

Thanks Tom, unfortunately the addresses are all relative so Chip's functions
didn't work for me, I ended-up writing a macro to loop through the rows
comparing each column to the master.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top