Hello all,
I am trying to count range of cells based on conditional formatted color;
I am loading a part of the data as shown in the attached spreadsheet. I found a VBA code online that I used which works with colored cells but does not give accurate result when the cells are conditionally formatted. for example, in the attached spreadsheet, Cell D2 is formatted using condional formatting, so the value in Cell B2 should be 1 and NOT 4. Please advise on how to tweak the code such that it works with conditional format.
Code used:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
Thanks
Bookmarks