Please need your help on count the cells value by different color specified.
In one sheet, some cells filled with red color, some cells filled with blue color, some cells filled with green color. The output should be cells count red color, cells count of blue color and cells count of green color separately.
This is what I've tried:
Function CountByColor(InputRange As Range, ColorRange As Range) As Long
Dim cl As Range
TempCount As Long
ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex TempCount = 0
For Each cl In InputRange.Cells
If cl.Interior.ColorIndex = ColorIndex
Then
TempCount = TempCount + 1
End If
Next cl
Set cl = Nothing CountByColor = TempCount
End Function
Your function works as expected:-
Formula:
Here
A2 Cell
is filled withGreen
and Green color index is14
Result:
For my sheet, I got the result as
Basically you need to execute this formula for three times to get three results