I have written the following code which is basically supposed colour some boxes accordingly. Whenever i run this code, it runs the first case i.e. even when some other case
An alternative is to use Select..Case
statements. I think it is a lot more readable for this kind of thing:
Select Case Sheet2.Range("B6").Value
Case 1, 2, 3
Range("D7").Select
With Selection.Interior
'.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
Sheet2.Cells(6, 11) = "rrrrrrr"
End With
Case 4, 5, 6, 7
Range("D7:E7").Select
With Selection.Interior
'.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
Sheet2.Cells(6, 12) = "rffffdffffdr"
End With
Case ....
....
Case Else
....
End Select