I need to count the cells in a range that contain a colour. the range may vary but I think I'm able to get the range anyway. I want to use a macro and not a formula. I have found the following formula and vba code function but need help modifying this so it will work by code and not formula. Can you please help? I cant workout the VBA code equivalent of the formula
thank you
smiler44
this does not work
dim gr as string
gr = CountColor(A1:A7, a1)
the formula is:
= CountColor(A1:A99, A1)
The function code is:
thank you
smiler44
this does not work
dim gr as string
gr = CountColor(A1:A7, a1)
the formula is:
= CountColor(A1:A99, A1)
The function code is:
Code:
Function CountColor(Rng As Range, RngColor As Range) As Integer
Dim Cll As Range
Dim Clr As Long
Clr = RngColor.Range("A1").Interior.Color
For Each Cll In Rng
If Cll.Interior.Color = Clr Then
CountColor = CountColor + 1
End If
Next Cll
End Function
Last edited: