+ Reply to Thread
Results 1 to 8 of 8

Ucase (VBA) - If "MS" then change color

Hybrid View

  1. #1
    Registered User
    Join Date
    12-22-2007
    Posts
    10

    Post Ucase (VBA) - If "MS" then change color

    Hi,

    I have at the moment (from anotehr project the below code);

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim icolor As Integer
    
        If Not Intersect(Target, Range("A1:K34")) Is Nothing Then
            Select Case UCase(Target)
                Case "W", "W.5"
                    icolor = 6
                Case Else
                    'Whatever
            End Select
            
            Target.Interior.ColorIndex = icolor
        End If
    
    End Sub

    Where the W is I want it to see Ms and change the color...but it's not working and I'll explain why..

    At the moment the code is looking for an exact match.. so if exact match is MS then color change...

    What I have is a list of names that will be pasted into a sheet.. and where the is a Ms (female) I want the color to change

    So when I change the W to Ms it only works if the cell has Ms ONLY...if it has Ms E Empty then it does not work?

    Anyone have experience with this than I do?

    Cheers ahead & have a happy new year.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This works for mee

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim icolor As Integer
    
        If Not Intersect(Target, Range("A1:K34")) Is Nothing Then
            Select Case UCase(Target)
                Case "MS"
                    icolor = 6
                Case Else
                    'Whatever
            End Select
            
            Target.Interior.ColorIndex = icolor
        End If
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-22-2007
    Posts
    10
    Thanks, but thats what I was trying to say in my first post.. if I put "MS", then thats ok if the cell has ONLY ms in it..if I put a name like "Ms Newman" then it does not work because that doce is looking for MS specifically....

    I need it to look at a name and if it has Ms in it, then do the action

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim icolor As Integer
    
    If Not Intersect(Target, Range("A1:K34")) Is Nothing Then
        Select Case True
            Case UCase(Target) Like "*MS*"
            icolor = 6
            Target.Interior.ColorIndex = icolor
        Case Else
            Target.Interior.ColorIndex = xlNone
    
        End Select
    End If
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Registered User
    Join Date
    12-22-2007
    Posts
    10

    Thumbs up

    Quote Originally Posted by VBA Noob
    Maybe

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim icolor As Integer
    
    If Not Intersect(Target, Range("A1:K34")) Is Nothing Then
        Select Case True
            Case UCase(Target) Like "*MS*"
            icolor = 6
            Target.Interior.ColorIndex = icolor
        Case Else
            Target.Interior.ColorIndex = xlNone
    
        End Select
    End If
    End Sub
    VBA Noob
    OMG that works !!

    Thanks a zillion dude !

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Your welcome

    VBA Noob

+ 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