Consulting

Results 1 to 3 of 3

Thread: Conditional Formatting range selection

  1. #1

    Conditional Formatting range selection

    Hi

    Have a code for conditional formatting


    HTML Code:
    Sub FormatTotalRow()
    
    Worksheets(1).Range("K1:K500").Select
    For Each c In Selection.Cells
    If c.Value >= 350 Then c.Resize(1, 4).Interior.ColorIndex = 50
    Next c
    
    End Sub
    The above code highlights results in the selected column as well as the following 4 columns 'Resize(1, 4)'
    How do you get the code to highlight 4 preceding columns

    Kindly help
    Best Regards

  2. #2
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    Sub FormatTotalRow()
    
    
    Worksheets(1).Range("K1:K500").Select
    For Each c In Selection.Cells
    If c.Value >= 350 Then c.Offset(0, -4).Interior.ColorIndex = 50
    Next c
    
    
    End Sub
    "To a man with a hammer everything looks like a nail." - Mark Twain

  3. #3
    Hi David

    Thanks for the quick reply
    Understood the code, and amended as follows

    HTML Code:
    Sub David()
    Worksheets(1).Range("K1:K15").Select
    For Each c In Selection.Cells
    If c.Value < 500 Then c.Offset(0, -4).Interior.ColorIndex = 50
    If c.Value < 500 Then c.Offset(0, -3).Interior.ColorIndex = 50
    If c.Value < 500 Then c.Offset(0, -2).Interior.ColorIndex = 50
    If c.Value < 500 Then c.Offset(0, -1).Interior.ColorIndex = 50
    Next c
    
    End Sub
    Thanks and Best Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •