Hi there,
I've recorded a macro in Excel 2007 which opens a file then highlights columns I to CH, then applies conditional formatting so that if a cell has a value of <0, it applies a red font with pink fill colour. Here's the code:
Formula:
Sub highlight()
'
' highlight Macro
'
'
ChDir "S:\Reports"
Workbooks.Open Filename:="S:\Reports\78weeks.xls"
Columns("I:I").Select
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 27
ActiveWindow.ScrollColumn = 29
ActiveWindow.ScrollColumn = 37
ActiveWindow.ScrollColumn = 40
ActiveWindow.ScrollColumn = 50
ActiveWindow.ScrollColumn = 54
ActiveWindow.ScrollColumn = 59
ActiveWindow.ScrollColumn = 60
ActiveWindow.ScrollColumn = 62
Columns("I:CH").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A1:A2").Select
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
The problem is, when I run it, it fails and hitting debug takes me to the below lines, highlighted.
Formula:
With Selection.FormatConditions(1).Font
.Color = -16383844
If anyone could point me in the right direction it would be greatly appreciated.
Bookmarks