I try to count all the cells in a range which have a specific color. In my case the color is green (ColorIndex
: 43). The color of the cells is conditioned by the conditional formatting.
My code is up to now as follows:
Function Count_color(range_data As Range, Farbe As Integer) As Integer
Dim datax As Range
Dim index As Integer
For Each datax In range_data
index = datax.DisplayFormat.Interior.ColorIndex
If index = Farbe Then
Count_color = Count_color + 1
End If
Next datax
End Function
In the cell I apply the function I get the error message "value". I would be really grateful for your help.
I corrected my code, but it did not answer your question exactly as it did not include conditional formatting.
Corrected code:
to check, use this formula:
However, if this solution does not satisfy you, I have a different function proposal for you that should meet your expectations. the only change that has happened is from ColorIndex to RGB. Values corresponding to ColorIndex = 43 = RGB (146,208,80). I substituted them as optional into the formula, or rather 2. and now you can type My_Count_Color_2 = (G1: G10) or My_Count_Color_2 = (G1: G10; 146; 208; 80)
Here is my code: