Refresh Pivot table

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
217
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

I am using the code below to refresh a pivot table, which is in another worksheet but in the same workbook, not sure what I am missing because it only works if I run it within Sales worksheet. I thought that using the whole object's hierarchy that would work.

VBA Code:
Sub RefreshSales()

    ActiveWorkbook.Sheets("Sales").PivotTables(1).PivotCache.Refresh
    ActiveWorkbook.Sheets("Sales").PivotTables(1).RefreshTable
    MsgBox "Refresh completed", vbInformation
  
End Sub
 
@DanteAmor - just curious as to why did you think that might help ?

Unless I am mistaken the only thing that does is to change whether items deleted still show in the filter dropdowns, with "None" resetting the list to only display current items.

1632231906962.png
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Did you by any chance rename the button after you added the code ?
Either go into the buttons properties or if you have only a few objects select the button and hit Alt+F10 to view the object property pane in Excel.
Thanks @Alex Blakenburg! Silly mistake from my side! Just had assing the incorrect sub, so when I was pushing the button to refresh sales, actually I was refresh the forecast o_O!! All good now!
 
Upvote 0
Try this:

VBA Code:
Sub RefreshSales()
    With ActiveWorkbook.Sheets("Sales").PivotTables(1)
      .PivotCache.MissingItemsLimit = xlMissingItemsNone
      .PivotCache.Refresh
      .RefreshTable
    End With
    MsgBox "Refresh completed", vbInformation
End Sub
Thanks @DanteAmor! That is a good piece of code to refresh pivot tables!!
 
Upvote 0

Forum statistics

Threads
1,214,894
Messages
6,122,124
Members
449,066
Latest member
Andyg666

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