I have several pivot tables that are identical. I want to change a filter that exists on all of them at the same time. Here is my code:
Sub ChangeTables()
Dim pt As PivotTable
Dim s As Worksheet
Application.Calculation = xlCalculationManual
For Each s In ThisWorkbook.Sheets ' For every tab
For Each pt In s.PivotTables ' For each pivot table
pt.PivotFields("SCENARIO").CurrentPage = "MyNewValue"
Next pt
Next s
Application.Calculation = xlCalculationSemiautomatic
End Sub
When I run this, the code executes but my pivot table filters are not changed. If I modify the code very slightly to print the current value of the filter to cells in my sheet, it works fine. Actually I started with the code that displays the values, then modified it to change the values.
Any reason why the filter does not change?
thanks
Fred Emmerich
Sub ChangeTables()
Dim pt As PivotTable
Dim s As Worksheet
Application.Calculation = xlCalculationManual
For Each s In ThisWorkbook.Sheets ' For every tab
For Each pt In s.PivotTables ' For each pivot table
pt.PivotFields("SCENARIO").CurrentPage = "MyNewValue"
Next pt
Next s
Application.Calculation = xlCalculationSemiautomatic
End Sub
When I run this, the code executes but my pivot table filters are not changed. If I modify the code very slightly to print the current value of the filter to cells in my sheet, it works fine. Actually I started with the code that displays the values, then modified it to change the values.
Any reason why the filter does not change?
thanks
Fred Emmerich