Option Explicit

Public Function CountColor(ByVal cells As Range, _
                           ByVal sample As Range) As Long
    Application.Volatile
    Dim cell As Range
    Dim count As Long
    For Each cell In cells.Cells
        If cell.Interior.Color = sample.Cells(1, 1).Interior.Color Then
            count = count + 1
        End If
    Next cell
    CountColor = count
End Function
