+ Reply to Thread
Results 1 to 13 of 13

conditional formatting with letters and numbers

Hybrid View

bta conditional formatting with... 01-27-2009, 04:13 PM
royUK Re: conditional formatting... 01-27-2009, 04:23 PM
bta Re: conditional formatting... 01-27-2009, 04:50 PM
Leith Ross Re: conditional formatting... 01-27-2009, 07:30 PM
bta Re: conditional formatting... 01-28-2009, 05:47 AM
royUK Re: conditional formatting... 01-28-2009, 05:58 AM
royUK Re: conditional formatting... 01-28-2009, 08:27 AM
bta Re: conditional formatting... 01-28-2009, 09:42 AM
Leith Ross Re: conditional formatting... 01-28-2009, 04:43 PM
bta Re: conditional formatting... 01-29-2009, 07:08 AM
bta Re: conditional formatting... 01-31-2009, 07:42 AM
  1. #1
    Registered User
    Join Date
    10-24-2008
    Location
    netherlands
    Posts
    35

    conditional formatting with letters and numbers

    Hi Gurus,
    I found out about conditional formatting for five different letters or letter combinations, using VBA, using the code below.
    I was wondering if this is also possible with letters or letter combinations, BV, RV, SV, CV, Z and numbers, somewhere between 0 and 9,5.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    For Each oCell In Target
            Select Case oCell.Value
                  Case Is = "BV"
                     oCell.Interior.ColorIndex = 4
                 Case Is = "RV"
                     oCell.Interior.ColorIndex = 2
                 Case Is = "SV"
                     oCell.Interior.ColorIndex = 2
                 Case Is = "CV"
                     oCell.Interior.ColorIndex = 2
                 Case Is = "ZV"
                     oCell.Interior.ColorIndex = 2
                  
             End Select
        Next oCell
    End Sub
    I hope you all understand what I mean.
    Thanks for your time.
    Greetings, Bengtar

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

    Re: conditional formatting with letters and numbers

    Do you mean that the numbers aren't always the same?
    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
    10-24-2008
    Location
    netherlands
    Posts
    35

    Re: conditional formatting with letters and numbers

    correct. Most of the times round numbers, sometimes not, can go up to 9,5.

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

    Re: conditional formatting with letters and numbers

    Hello bta,

    I assume the numbers are not combined with the letters. If you do have letters and numbers together, where the numbers vary between 0 and 9.5, then a different macro is needed.
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    For Each oCell In Target
            Select Case oCell.Value
                  Case Is = "BV"
                     oCell.Interior.ColorIndex = 4
                 Case Is = "RV", "SV", "CV", "ZV"
                     oCell.Interior.ColorIndex = 2
                 Case 0 To 9.5                        'Change the period to comma
                     oCell.Interior.ColorIndex = 6  'Change this color to whatever you are using
             End Select
        Next oCell
    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!)

  5. #5
    Registered User
    Join Date
    10-24-2008
    Location
    netherlands
    Posts
    35

    Re: conditional formatting with letters and numbers

    Thank you Leith,
    Unfortunately for some reason if I delete the contents of a cell, the cell remains yellow if I delete a letter combination or turns yellow if i delete a number.
    Any idea?
    Thanks for your time, Bengtar

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

    Re: conditional formatting with letters and numbers

    Hello bta,

    It is happening because those conditions equate to zero. The final Case statement tests for zero and the true condition colors the cell yellow. He final compare need to be changed...
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    For Each oCell In Target
            Select Case oCell.Value
                  Case Is = "BV"
                     oCell.Interior.ColorIndex = 4
                 Case Is = "RV", "SV", "CV", "ZV"
                     oCell.Interior.ColorIndex = 2
                 Case Is > 0  
                     If oCell.Value < 9,5 Then                       
                        oCell.Interior.ColorIndex = 6 
                     End If
             End Select
        Next oCell
    End Sub

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

    Re: conditional formatting with letters and numbers

    Maybe
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    For Each oCell In Target
            Select Case oCell.Value
                  Case Is = "BV"
                     oCell.Interior.ColorIndex = 4
                 Case Is = "RV", "SV", "CV", "ZV"
                     oCell.Interior.ColorIndex = 2
                 Case 0 To 9.5                        'Change the period to comma
                     oCell.Interior.ColorIndex = 6  'Change this color to whatever you are using
                 Case Else
                     oCell.Interior.ColorIndex = xlNone
    End Select
        Next oCell
    End Sub

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

    Re: conditional formatting with letters and numbers

    Can you attach the workbook.

  9. #9
    Registered User
    Join Date
    10-24-2008
    Location
    netherlands
    Posts
    35

    Re: conditional formatting with letters and numbers

    Quote Originally Posted by royUK View Post
    Can you attach the workbook.
    BTA-condform-v1.zip

    vba-password is bta

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

    Re: conditional formatting with letters and numbers

    Hello bta,

    There is problem with the file. When I try to open it, WinZip says the file is not a valid archive. Can you can zip it again and repost the file? Thanks.

  11. #11
    Registered User
    Join Date
    10-24-2008
    Location
    netherlands
    Posts
    35

    Re: conditional formatting with letters and numbers

    Ok, retry please.
    BTA-condform-v1.zip

  12. #12
    Registered User
    Join Date
    10-24-2008
    Location
    netherlands
    Posts
    35

    Re: conditional formatting with letters and numbers

    Anybody give it a try?

+ 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