PDA

View Full Version : Extended Conditional Formatting



mjg060468
01-25-2010, 09:09 AM
Hi need help.

Have a spreadsheet that requires a range of cells to change colour based on the numbers entered. eg. b2:g2 against the targets entered in b1:g1

If the number entered in b2 is <50% of b1 then cell is red
If number entered in b2 is >=50%<=75% of b1 then cell is orange
If number entered in b2 is >75% of b1 then cell is green.
If blank then cell is white

This will then need to be copied across range of cells eg b2:g2

Can anyone help me, please!:help

Bob Phillips
01-25-2010, 09:56 AM
You could use conditional formatting, or this event code



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Me.Range("B2:G2")) Is Nothing Then

With Target

Select Case .Value

Case Is = "": .Offset(-1, 0).Interior.ColorIndex = xlColorIndexNone
Case Is < 0.5: .Offset(-1, 0).Interior.ColorIndex = 3
Case Is < 0.75: .Offset(-1, 0).Interior.ColorIndex = 46
Case Else: .Offset(-1, 0).Interior.ColorIndex = 10
End Select
End With
End If
End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.