Pivot Table & VBA Code

kishorkhanal

Active Member
Joined
Mar 23, 2006
Messages
434
I am using following code to update the pivot tables in another worksheet, when I select a worksheet. I have about 7 Pivot Tables that use the same source data. It takes a little while to update all 7 pivot tables after I select the sheet. Is it possible to make the update much faster?

Privatse Sub Worksheet_Activate()
Worksheets("Pivots").PivotTables("PivotTable1").RefreshTable
Worksheets("Pivots").PivotTables("PivotTable3").RefreshTable
Worksheets("Pivots").PivotTables("PivotTable4").RefreshTable
Worksheets("Pivots").PivotTables("PivotTable5").RefreshTable
Worksheets("Pivots").PivotTables("PivotTable7").RefreshTable
Worksheets("Pivots").PivotTables("PivotTable8").RefreshTable
Worksheets("Pivots").PivotTables("PivotTable9").RefreshTable
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Instead of updating individual pivot tables, is it possible to update all the pivot tables in that sheet? Will it make it any faster? Please help.
 
Upvote 0
Hi

Try this. Copy the code in a macro, select the sheet with the pivot tables in and run it.

Dim pt As PivotTable
Worksheets("Pivots").Activate
For Each pt In ActiveSheet.PivotTables
pt.RefreshTable
Next pt

End Sub
 
Upvote 0
Hi

Try this. Copy the code in a macro, select the sheet with the pivot tables in and run it.

Dim pt As PivotTable
Worksheets("Pivots").Activate
For Each pt In ActiveSheet.PivotTables
pt.RefreshTable
Next pt

End Sub

How can I make the pivots update automatically using this code when I select the Worksheet "Filter"?
 
Upvote 0
I'm not sure what you mean? Are you currently filtering to select specific information and then updating your pivots?

If you are, you could do someting similar to the code below prior to updating the pivots...:

Selection.AutoFilter Field:=11, Criteria1:="BEDFORD"
Selection.AutoFilter Field:=7, Criteria1:="Attribution Agreed"
 
Upvote 0
Drop this piece of code to the sheet module (= click on the sheet name on the VBA Project window) of the worksheet "Filter":
Code:
Private Sub Worksheet_Activate()

Dim pt As PivotTable

For Each pt In ActiveSheet.PivotTables
    pt.RefreshTable
Next pt

End Sub
 
Upvote 0
What do you mean it does not work? I mean have you added rows to your data and it's not picking up the new rows? And you have pasted the code in the sheet module and not in the normal module, right?

If your Pivot Tables were done using fixed ranges updating the tables won't expand the data range. It only gets the values from the given range and makes sure it's up to date.

If you want your Pivot Tables to pick up all the new lines of data you should use dynamic ranges to start with.

But if this isn't the case and you've changed your existing data range values and your pivot tables are still not updating, then I don't know what's the problem without seeing the file. The code seems to be working fine.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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