PDA

View Full Version : [SOLVED] Conditional Formatting range selection



parttime_guy
08-27-2018, 08:52 PM
Hi

Have a code for conditional formatting




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 :banghead:

Kindly help
Best Regards

david000
08-27-2018, 09:14 PM
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

parttime_guy
08-27-2018, 09:49 PM
Hi David

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




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 : pray2::friends::bow: