I have a few conditional formatting conditions on my excel sheet that fill in cells with different colors. I am trying to count the number of cells colored by my conditional formatting in excel so that I can check their proportions, but for some reason, it keeps returning 0 no matter what. Here is my VBA function:
Function CountCellsByColor(data_range As Range, cell_color As Range)
Dim cell As Range
Dim cnt As Integer
cnt = 0
For Each cell In data_range
If cell_color.Interior.Color = cell.Interior.Color Then
cnt = cnt + 1
End If
Next cell
CountCellsByColor = cnt
End Function
I have 4 different conditions that fill in the colors of the cells, and none of them are detected by this function. When I make the function count white cells over a range, it counts them just fine. Is it just the case that when dealing with conditional formatting, it gives it a "fake" color that is not detectable in this way? Or is there something else going wrong with my code or otherwise?
Thank you so much for the help!