tbilderbac
New Member
- Joined
- Apr 11, 2022
- Messages
- 28
- Office Version
- 365
- Platform
- Windows
- MacOS
I have a spreadsheet that I am inputting golf scores in and for certain colors I am wanting to auto count that color. I got some code that should count the number of red cells [Conditional formatting] in the row. The formula is =CountByColor(G18:X18,E2) but it is not counting up the red cells? I have the target cell conditionally formatted to the color red so it should be working?
Public Function CountByColor(CellRange As Range, TargetCell As Range)
Dim TargetColor As Long, Count As Long, C As Range
TargetColor = TargetCell.DisplayFormat.Interior.Color
For Each C In CellRange
If C.DisplayFormat.Color = TargetColor Then Count = Count + 1
Next C
CountByColor = Count
Public Function CountByColor(CellRange As Range, TargetCell As Range)
Dim TargetColor As Long, Count As Long, C As Range
TargetColor = TargetCell.DisplayFormat.Interior.Color
For Each C In CellRange
If C.DisplayFormat.Color = TargetColor Then Count = Count + 1
Next C
CountByColor = Count