HI QuietMan,
I'm not sure what you mean by update. If all you need to do is take into
account that the underlying data has changed for the Pivot Table then this
should work:
ActiveSheet.PivotTables(1).PivotCache.Refresh
If you need to change the all formulas so the basic calculation is different
then something like this would work:
'delete all existing formulas
For Each PT In ActiveSheet.PivotTables
For Each CF In PT.CalculatedFields
CF.Delete
Next
Next
'add new formulas
With ActiveSheet.PivotTables(1)
.CalculatedFields.Add "Field1", "=C/B", True
.PivotFields("FIELD1").Orientation = xlDataField
.CalculatedFields.Add "Field2", "=C+B", True
.PivotFields("FIELD2").Orientation = xlDataField
.CalculatedFields.Add "Field3", "=C - B", True
.PivotFields("FIELD3").Orientation = xlDataField
End With
End Sub
If you need to change only certain formulas then address those fields by
name -
with ActiveSheet.PivotTables("PivotTable1")
.CalculatedFields("Field2").StandardFormula = "=C-B"
end with
This changes Field2's calculation form c+b to c - b. Notice the double =
signs after standardformula.
Similar code works for calculated items.
Regards,
Mike