Trouble Changing Pivot Table Source

hawkinsr86

New Member
Joined
Aug 10, 2012
Messages
24
Hi guys,

I have about 8 worksheets in a workbook, all of which have pivot tables that link to the same data set. I want a piece of code that changes the data source of each pivot. Here is the code i am using

Sub RefreshPivotTables()


Dim ws As Worksheet
Dim PT As PivotTable
Dim SourceName As String


SourceName = shtData.Range("N2") ' this value is Data!$B$3:$W$3591


For Each ws In ActiveWorkbook.Worksheets
For Each PT In ws.PivotTables
PT.SourceData = SourceName
Next PT
Next ws


ActiveWorkbook.RefreshAll
End Sub

Thanks in adavnce
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,216,122
Messages
6,128,958
Members
449,480
Latest member
yesitisasport

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