Conditional Formatting According to Text

  • Hi there


    I have been reading the code for conditinal formatting, so it's posible to have more than 3 rules (see below):



    This one is for numbers but I have text instead. I have different kind of text that I find with lookup. Now I want to color the cell according to the text that I find during the lookup.


    Regards
    Alring

  • Re: Conditinal formatting according to text


    Something like this

  • Re: Conditinal formatting according to text


    Hi Roy


    It seems that it's only working when I write text in Range (A1:A10). But I don't write text in these cells. I make a vlookup and the result from there is written in cella A1:A10. And when I do that then the color don't change.


    regards
    Alring

  • Re: Conditinal formatting according to text


    Alring


    The code posted will only work when a cell is manually changed.


    It appears from your workbook that you want to format the result of a formula.

    Boo!:yikes:

  • Re: Conditinal formatting according to text


    I used isnumber because I didn't wnat to have N/A written in the cell.

  • Re: Conditinal formatting according to text


    Hi Norie


    Thats true. Is that possible??

  • Re: Conditinal formatting according to text


    Try this event


    [vba]
    Private Sub Worksheet_Calculate()
    Dim icolor As Integer
    Dim MyText As String
    Dim Target As Range

    For Each Target In Range("A1:A10")

    MyText = Target.Value
    Select Case MyText
    Case "Yes"
    icolor = 6
    Case "No"
    icolor = 12
    Case "Not sure"
    icolor = 7
    Case "Don't care"
    icolor = 53
    Case "Why?"
    icolor = 15
    Case "Possibly"
    icolor = 42
    Case Else
    'Whatever
    End Select

    Target.Interior.ColorIndex = icolor
    Next Target

    End Sub
    [/vba]

    HTH


    Bob

  • Re: Conditinal formatting according to text


    Hi Bob


    If I write the code like this then it works



    If I don't write


    Code
    Case Else
                 icolor = 2


    Then will all the cells that is ampty under one cell that is not empty be the same color as the one above.


    Alring

  • Re: Conditinal formatting according to text


    Hi Bob


    Beside that then was it a very good code you wrote.


    Thanks :thanx:


    Alring

  • Re: Conditinal formatting according to text



    No, they should remain untouched.

    HTH


    Bob

  • Re: Conditinal formatting according to text


    Hi Bob


    I have found out that it's better to write


    Code
    Case Else 
        icolor = none


    If there is only text in cell A1 then the other cells will get the same color as A1.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!