+ Reply to Thread
Results 1 to 8 of 8

conditional formatting question

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2004
    Posts
    17

    conditional formatting question

    Hi,
    I have data supplied to me as: 36/40. In this example, 36 is a person's average score & 40 is the most recent score. In a column of such figures, is it possible to have conditional formatting highlight just the highest recent score? I realize the simplest solution is to split these figures into 2 columns, but would rather rather keep them intact if possible.

    Fujimi-cho

  2. #2
    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
    Don't think you can with CF.

    Here's a macro that bolds the last 2 digits if greater than the first 2 for each cell in your selection

    Link on where to add code

    Sub xxx()
    Dim Cel As Range
    For Each Cel In Selection
    If Right(Cel, 2) > Left(Cel, 2) Then
    With Cel.Characters(Start:=4, Length:=5).Font
           .FontStyle = "Bold"
    End With
    End If
    Next Cel
    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 !!!

  3. #3
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Hi Fujimi-cho,

    This can't be done by just using Excel's Conditional Format option. But with VBA it is possible as you can see in the attached file.

    Select the range with scores and click the button.

    Succes,
    Erik
    Attached Files Attached Files
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  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
    I assume you don't want to press a button so try this event macro

    You can either open the attached example or right click your sheet tab > select view code and paste in the below. It works on Col A and makes it bold and red ColorIndex 3.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
    If Right(Target, 2) > Left(Target, 2) Then
    With Target.Characters(Start:=4, Length:=5).Font
           .FontStyle = "Bold"
           .ColorIndex = 3
    End With
    Else
    With Target.Font
           .FontStyle = False
           .ColorIndex = xlAutomatic
    End With
    End If
    End If
    
    End Sub
    VBA Noob
    Attached Files Attached Files

  5. #5
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    You don't take into account the possibility that the scores are < 10 and/or > 99 VBA Noob.

  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
    Thanks WinteE,

    Now amended

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Dim i As Integer
    On Error GoTo trap:
    i = WorksheetFunction.Find("/", Target)
    If Val(Right(Target, Len(Target) - i)) _
    > Val(Left(Target, i - 1)) Then
    With Target.Characters(Start:=i + 1, Length:=999).Font
           .FontStyle = "Bold"
           .ColorIndex = 3
    End With
    Else
    With Target.Font
           .FontStyle = False
           .ColorIndex = xlAutomatic
    End With
    End If
    End If
    trap:
    End Sub
    VBA Noob

  7. #7
    Registered User
    Join Date
    09-27-2004
    Posts
    17
    Thanks to VBA Noob & winteE; y'all confirmed my doubts about conditional formatting doing the job. I'll give your suggestions a try!

    Fujimi-cho

+ 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