Color

  • Thread starter Thread starter Angeles
  • Start date Start date
A

Angeles

Is is possible to define a condition depending of the text color of cells ?

Thank you
 
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---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top