I have this UDF which counts the number of cells with a specific colour.

Function CountColour(rColor As Range, rCOuntRange As Range)

Dim rCell As Range
Dim iCol As Integer
Dim vResult

iCol = rColor.Interior.ColorIndex

For Each rCell In rCOuntRange
If rCell.Interior.ColorIndex = iCol Then
vResult = vResult + 1
End If
Next rCell

CountColour = vResult
End Function
It works fine unless the colours are very similar to each other. Why is this? Any way to sort it out?