Many years ago, I found this incredibly helpful piece of code that I have used hundreds of times since:
I use it with a formula like this:
Where AH1 is a fill color I've defined, then it looks in AF2:AG2 for matching fill colors, and gives me a count of the matches.
However, It seems it does not work with conditional formatting. Is there a solution to this?
Thanks
VBA Code:
Function GetColorCount(CountRange As Range, CountColor As Range)
Dim CountColorValue As Integer
Dim TotalCount As Integer
CountColorValue = CountColor.Interior.ColorIndex
Set rCell = CountRange
For Each rCell In CountRange
If rCell.Interior.ColorIndex = CountColorValue Then
TotalCount = TotalCount + 1
End If
Next rCell
GetColorCount = TotalCount
End Function
I use it with a formula like this:
Excel Formula:
=@GetColorCount($AF2:$AG2,$AH$1)
Where AH1 is a fill color I've defined, then it looks in AF2:AG2 for matching fill colors, and gives me a count of the matches.
However, It seems it does not work with conditional formatting. Is there a solution to this?
Thanks