Hello All,

I am working on some project where i stuck up basically i needed the VBA code which runs and count the number of cells which have specific color as defined by me. But any how my VBA code is doing that thing but it is also calculating the blanks cells with the same color but i need to count only those who are contain the data or value in it. Please refer the below screenshot for your reference.

aa.JPG

In This i am getting the count 15 (it is counting blank cells as well) but the required needed is 5. (I am counting the S.No.)

Using code:
Function COLORCOUNT(varRange As Range, varColor As Range)
Dim cell As Range
For Each cell In varRange
If cell.Interior.ColorIndex = varColor.Interior.ColorIndex Then
ColorCount = ColorCount + 1
End If
Next
End Function
=COLORCOUNT(A1:A10,B1)
In the above function B1 is refering to color which i needed to be counted.

Please help with the above scenario asap as my project is stuck.