Pivot Table SourceData Update

KMacattack

New Member
Joined
Nov 24, 2008
Messages
11
Is there a way to redefine the Sourcedata for each pivottable using VBA. I am trying to make sure that i can get the excel workbook as small as possible, i have a lot of pivot tables in the workbook.

so i would want something like this:

Code:
Sub PT_Update()
Dim sht As Worksheet
Dim PT As PivotTable
For Each sht In ActiveWorkbook.Sheets
     For Each PT In sht.PivotTables
        PT.PivotCache.SourceData = "PivotTable1"
     Next
Next
End Sub

but I am getting an error.
Please help.

Thank you
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I think that your problem is with the use of "PivotTable1", referring to the pivottable instead of the pivot table's data source.

I would give the sourcedata (the table for the pivot tables) a "name" by highlighting the entire table including the headings, clicking in the Name Box (above Cell A1), typing something like "MyTable" (without spaces) and pressing the Enter key.

The code would then be:
Code:
PT.PivotCache.SourceData = "MyTable"
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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