I tried to write a macro to format my excel file.
There are numbers in column G and the numbers range between 1 to 99 (all are integers). My target is to shade the row with color green when the number is equal to or less than 30, grassgreen when it's between 31 and 40, yellow when it's larger than 41 but less than 45. my code is as follows but it did not work, can anyone give me help?
Thanks a lot.
There are numbers in column G and the numbers range between 1 to 99 (all are integers). My target is to shade the row with color green when the number is equal to or less than 30, grassgreen when it's between 31 and 40, yellow when it's larger than 41 but less than 45. my code is as follows but it did not work, can anyone give me help?
Thanks a lot.
Code:
ActiveSheet.UsedRange.Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$G2<45.1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$G2<40.1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$G2<30.1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False