Public Function CountColor(rng As Range, COLOR As String) As Long
'Precondition: rng must be a valid, non-empty range, and
'color must be either BLACK or RED
'Postcondition: Function counts the number of cells which have font color
'as specified by the 'COLOR' argument, and returns value to the cell containing
'the formula.
'declarations
Dim c As Range
Dim cindex As Integer, x As Long
'correct for appropriate case sensitivity
COLOR = UCase(COLOR)
For Each c In rng
Select Case COLOR
Case "RED"
If c.Font.ColorIndex = 3 Then
x = x + 1
End If
Case "BLACK"
If c.Font.ColorIndex = 1 Or c.Font.ColorIndex = xlNone Then
x = x + 1
End If
Case Else
'Catches invalid inputs for the COLOR paramater
MsgBox "Invalid input, color must be either 'RED' or 'BLACK'."
End Select
Next c
CountColor = x
End Function