macro to refresh pivot table

ericlch16

Active Member
Joined
Nov 2, 2007
Messages
313
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
I have one workbook which contains about 10 sheets.

most of the sheets have pivot table in it. some of them has two pivot table next to each other.

i need a macro which will refresh all pivot table when the new data is pasted in the data sheet.

Also there is a filter for each pivot table which is called "centre" which can have values a, b, c, d, e. I want the macro to select "a" for all pivots in that workbook.



Any idea?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I've not tried this code but are you looking at something like this:

Dim PT as PivotTable
Dim WS as Worksheet

Sub test()

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT in WS.PivotTables
PT.PivotCache.Refresh
Next PT
Next WS

End Sub
 
Upvote 0
how to make sure a pivotfield("centre") is a for all pivot table?
 
Upvote 0
Hey, try this:

Dim PT as PivotTable
Dim WS as Worksheet

Sub test()

For Each WS In ThisWorkbook.Worksheets
For Each PT in WS.PivotTables
PT.PivotCache.Refresh
PT.Pivotfields("Centre").CurrentPage="A"
Next PT
Next WS

End Sub

let me know if that does what you want it to
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

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