Is there a cleaner, faster way to for my code to take this:
Excel 2007
and with click of a button get it conditionally formatted as follows:
(This code works, I was just looking for a better way)
Excel Workbook | |||
---|---|---|---|
G | |||
1 | Days Open | ||
2 | 2 | ||
3 | 10 | ||
4 | 11 | ||
5 | 11 | ||
6 | 11 | ||
7 | 11 | ||
8 | 15 | ||
9 | 15 | ||
10 | 15 | ||
11 | 21 | ||
12 | 22 | ||
13 | 23 | ||
14 | 23 | ||
15 | 24 | ||
16 | 29 | ||
17 | 67 | ||
18 | 87 | ||
19 | 95 | ||
20 | 105 | ||
working |
and with click of a button get it conditionally formatted as follows:
(This code works, I was just looking for a better way)
Code:
Private Sub cmdDaysOpn_Click()
Dim lLastRow As Long
With ActiveSheet
'find the last row in the worksheet
lLastRow = Get_Last_Row(.Cells)
End With
'Select the Used Range in column G
With ActiveSheet.Range("G2:G" & lLastRow).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="=89"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 3
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=60", Formula2:="=89"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 27
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=60"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 4
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End With
End With
End Sub