Change data source in pivot table

adr12345

Board Regular
Joined
Jan 19, 2015
Messages
67
I am trying to change data source of pivot table.
Below is the code.

Dim data1 As PivotCache
Dim PT2 As PivotTable
Sheets("carrierresponse_list").Select
Set data1 = ActiveWorkbook.PivotCaches.Create(xlDatabase, Sheets("carrierresponse_list").range("A1", range("A1").End(xlToRight).End(xlDown)).Address(, , xlR1C1))
Set PT2 = data.CreatePivotTable(Worksheets("Tables").range("B23"))


Earlier in this code I have used "Dim data as pivotcache", which is referring to another sheet. And again I used "data1" variable.
But later part is not taking the new reference in pivot table.

Can anyone tell where's the error?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Is this the error?

Code:
Sub interm()
Dim data1 As PivotCache, PT2 As PivotTable
Sheets("carrierresponse_list").Activate
Set data1 = ActiveWorkbook.PivotCaches.Create(xlDatabase, _
Sheets("carrierresponse_list").Range("A1", Range("A1").End(xlToRight).End(xlDown)).Address(, , xlR1C1))


Set PT2 =[COLOR=#ff8c00] data1.[/COLOR]CreatePivotTable(Worksheets("Tables").Range("B23"))


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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