Using vb to assign cell formating

  • Hi Everyone,


    Someone yesterday kindly helped with a scenario where if i entered 1 in a cell it would turn yellow.


    Is there a way that if i entered 1m for example it would turn yellow?
    My current code is this:


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count = 1 Then
    Select Case Target
    Case 1
    Target.Interior.ColorIndex = 6
    'yellow
    Case 2
    Target.Interior.ColorIndex = 41
    Case Else
    Target.Interior.ColorIndex = xlNone
    End Select
    End If
    End Sub

  • Steve, try the following change to your code


    Where you have Case 1 change it to Case 1 & "m"


    And similar changes to the other case!


    It works for me


    Good luck


    Ray

    ________________________________________


    Good Luck!


    Ray :nana:

  • thanks for that, do you know how to hide the letters


    so for example i enter 1m and it should just show the 1 with the colour.



    i.e o = yellow, so i enter 1o, it changes the cell to yellow but the o disappears(changes to yellow, maybe thats what it should do?) so the final outcome is the cell shows 1 and is yellow!

  • Steve, try this



    Good Luck


    Ray

    ________________________________________


    Good Luck!


    Ray :nana:

Participate now!

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