-
1
- #1
MasterofNone
Technical User
The following VBA code was copied from a previous thread (this code is from acron, many thanks for getting me started):
Conditional Formatting cannot manage more that 3 conditions, so you must resort to VBA. How to approachh that best depends on how the values of the range in question are updated. Presumably it is a result of formulas, in which case trapping th esheet calculate event should assist. The following code does that :
Private Sub Worksheet_Calculate()
Dim oCell As Rang
For Each oCell In Range("A1:A20")
Select Case oCell.Value
Case Is < 1
oCell.Interior.ColorIndex = xlNone
Case Is = 1
oCell.Interior.ColorIndex = 5
Case Is = 2
oCell.Interior.ColorIndex = 3
Case Is = 3
oCell.Interior.ColorIndex = 6
Case Is = 4
oCell.Interior.ColorIndex = 4
Case Is = 5
oCell.Interior.ColorIndex = 7
Case Is = 6
oCell.Interior.ColorIndex = 15
Case Is = 7
oCell.Interior.ColorIndex = 40
Case Is > 7
oCell.Interior.ColorIndex = xlNone
End Select
Next oCell
End Sub
This nearly answers my issue but not quite. I have a list of data, eg A1:H50. The conditioning information is stored in column C. What I would like to do is format the row of information should the condition be met. i.e. if C3 =3 then it would format A3:H3. Any idea's? All help gratefully received
Conditional Formatting cannot manage more that 3 conditions, so you must resort to VBA. How to approachh that best depends on how the values of the range in question are updated. Presumably it is a result of formulas, in which case trapping th esheet calculate event should assist. The following code does that :
Private Sub Worksheet_Calculate()
Dim oCell As Rang
For Each oCell In Range("A1:A20")
Select Case oCell.Value
Case Is < 1
oCell.Interior.ColorIndex = xlNone
Case Is = 1
oCell.Interior.ColorIndex = 5
Case Is = 2
oCell.Interior.ColorIndex = 3
Case Is = 3
oCell.Interior.ColorIndex = 6
Case Is = 4
oCell.Interior.ColorIndex = 4
Case Is = 5
oCell.Interior.ColorIndex = 7
Case Is = 6
oCell.Interior.ColorIndex = 15
Case Is = 7
oCell.Interior.ColorIndex = 40
Case Is > 7
oCell.Interior.ColorIndex = xlNone
End Select
Next oCell
End Sub
This nearly answers my issue but not quite. I have a list of data, eg A1:H50. The conditioning information is stored in column C. What I would like to do is format the row of information should the condition be met. i.e. if C3 =3 then it would format A3:H3. Any idea's? All help gratefully received