Macro to refresh all Pivot tables in EXCEL 2013

James Hodgson

New Member
Joined
Jun 11, 2015
Messages
1
Hi All

Hopefully this is simple.

I have a large number of pivot tables that my lookups use. I want to create a button to update all so that I don't forget any.

I used this macro code which I found on this website (MR Excel):

Sub RefreshAll()
Dim pvt As PivotTable
Dim sh As Worksheet

For Each sh In Worksheets
For Each pvt In sh.PivotTables
pvt.RefreshTable
Next pvt
Next sh

End Sub

I created the button. I linked the Macro to the button. When I click the button I get the following error:

Run-time error 1004 - the pivot table field name is not valid. To create a pivot table report, you must use data that is organized as a list with labelled columns. If you are changing the name of a pivot table field, you must type a new name for the field.

When I run the debug - it tells me that the code line causing issue is "pvt.RefreshTable"

Any help would be appreciated.

Thanks
James
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Pivot tables use the top row as field names. One way you can get this error is if a cell on the top row is blank and you are using that column in a PivotTable.
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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