Color

  • Thread starter Thread starter Angeles
  • Start date Start date
This may give you what you want:
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = 3)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function

Code is from:
http://www.cpearson.com/excel/colors.htm

Call it in the following manner:
=CountByColor(A1:F5,3,TRUE)
Notice, this is for text colored red, which Excel recognizes as 3.

Regards,
Ryan---
 
Back
Top