I have the following code in an Excel Worksheet for Conditional Formatting...
Here, the Selections are different parts of a Pivot Table. This code works absolutely fine in Excel 2003 but not in Excel 2007.
In Excel 2007 the FormatConditions(3).Font.ColorIndex gets applied to FormatCondtion(1)! I have no idea why this is happening! Any help would be greatly appreciated.
Note: If I apply the same formula on a normal data it works fine. But on a Pivot table data it isn't working.
Also when I manually add conditional format on the data it works, but with the Macro it isn't.
Code:
Sub setConFormat(intLL, intTar) 'intLL=0.77 and intTar=0.8
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
, Formula1:=CStr(intTar)
.FormatConditions(1).Font.ColorIndex = 1
.FormatConditions(1).Interior.ColorIndex = 43
.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:=CStr(intLL), Formula2:=CStr(intTar)
.FormatConditions(2).Font.ColorIndex = 1
.FormatConditions(2).Interior.ColorIndex = 44
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:=CStr(intLL)
.FormatConditions(3).Font.ColorIndex = 2
.FormatConditions(3).Interior.ColorIndex = 1
End With
End Sub
In Excel 2007 the FormatConditions(3).Font.ColorIndex gets applied to FormatCondtion(1)! I have no idea why this is happening! Any help would be greatly appreciated.
Note: If I apply the same formula on a normal data it works fine. But on a Pivot table data it isn't working.
Also when I manually add conditional format on the data it works, but with the Macro it isn't.