Conditional Formatting on Pivot Data in Excel 2007 using VBA

vshankaa

New Member
Joined
Apr 13, 2010
Messages
1
I have the following code in an Excel Worksheet for Conditional Formatting...
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
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.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,215,622
Messages
6,125,886
Members
449,269
Latest member
GBCOACW

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top