Pivot Table(s) - refresh in sheet - macro - automate
Pepe,
Sub RefreshAllPTs()
Dim myPT As PivotTable
For Each myPT In Sheets("Info1").PivotTables
myPT.PivotCache.Refresh
Next
End Sub
The best way to deal with pivot table ranges is to define the range at least one row longer than the
data, shade the data cells, and make sure that when you need to insert more data, you start by
inserting new rows at the first empty but shaded row. Then Excel will automatically expand the PT
range.
HTH,
Bernie
MS Excel MVP
"pepenacho" wrote in message
...
Hello:
I have two tables, in separate Work Sheets: Table1 and Table2.
- Table1 and Table2 are periodically updated. Generally only the number of
rows changes, up or down.
I have a separate Work Sheet called Info1. There I slice and dice the data
from both tables, with the use of 3 Pivot Tables, which were created
side-by-side. I will have Work Sheet with pivots, called: Info2, Info3, etc.
Question 1:
The toolbar offers a button to refresh a Pivot table. I recorded the
procedure (using a macro) called it PivotUPDT.
Sub PivotUPDT()
ActiveSheet.PivotTables("PivotTable1").PivotCache. Refresh
End Sub
How do I tweak so that this procedure refreshes any and all Pivot Tables, in
an active Work Sheet, be it Info1, Info 2 or Info 3?
"PivotTable1" suggests only the first Pivot Table that was created will be
refreshed.
Question 2:
If the boundy of my Table1 or Table2 changes (i.e. less rows are present
than before).
In Info1, for example, I want to be able to update the range that a Pivot
Table is mapped to. What is the code for that? I'm ok with making a button
for each Pivot Table in Info1 as long as I know how to do it.
Thanks,
Pepe
|