Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Colors 1

Status
Not open for further replies.

egodette

Technical User
Jun 12, 2002
222
US
I need to programmatically determine the color of text in a spread sheet.

Any Ideas?
 
Have a look at the Font.ColorIndex property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's a custom function adapted from something I've used before:
Code:
Function TextColor(rCell As Range, Optional ColorName As Boolean)
Dim strColor As String, iIndexNum As Integer

Select Case rCell.Interior.ColorIndex
   Case 10
    strColor = "Green"
    iIndexNum = 10
   Case 3
    strColor = "Red"
    iIndexNum = 3
  Case Else
    strColor = "Other"
End Select

    If ColorName = True Or _
        strColor = "Other"
    Then
        TextColor = strColor
    Else
        TextColor = iIndexNum
    End If

End Function
Can be used as
[tab]=TextColor(A1)
to return 10 if green, or include the second argument:
[tab]=TextColor(A1,1)
to return the word "Green".

Once you have that in place, you can wrap it in an if, like this:
[tab]=If(TextColor(A1)=10, B1+A1, If(TextColor(A1)=3, B1-A1, [Whatever You Want To Happen If The Text Color Isn't Red OR Green]))

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top