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?
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?