+ Reply to Thread
Results 1 to 2 of 2

Check for Font Color

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-27-2004
    Posts
    133

    Question Check for Font Color

    I want to test a particular cell or cells for font color. For example if the color is red perform some action. If the color is balck then write "PASS".

    This seems simple enough but my test code below doesn't work.
    1) I selected a cell
    2) Printed the word "message"
    3) Changed the font color to red
    4) Test for black
    5) If black, pront "Pass" in adjacent cell

    Obvioulsly doing something wrong. I beiieve the values for the colots, 3 for red and 0 for black are correct. Any suggestions?

    Sub Macro1()
    
        Range("U48").Select
        ActiveCell.FormulaR1C1 = "message"
        Selection.Font.ColorIndex = 3
        
        If ActiveCell.Font.ColorIndex = 0 Then
            Range("U49").Value = "PASS"
        End If
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Check for Font Color

    Hello scantor145,

    You were close. The color index for black is one. The cells adjacent to U48 are T48 and V48. I used V48. Rarely is necessary to select or activate an object in VBA code.
    Sub Macro1()
    
    Dim Rng As Range
    
      Set Rng = Range("U48")
        Rng = "message"
        Rng.Font.ColorIndex = 3
        
        If Rng.Font.ColorIndex = 1 Then
            Rng.Offset(0, 1) = "PASS"
        End If
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1