• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Pivot Data Source Change Error "method pivottables of object _worksheet failed"

Nitesh Khot

Member
Unable to change Existing Pivot Table data source..

Getting error "method pivottables of object _worksheet failed"

Code:
Set Pivot_sht = ThisWorkbook.Sheets("Summary")
Pivot_sht.PivotTables("Manpower").ChangePivotCache _
                 ThisWorkbook.PivotCaches.Create( _
                 SourceType:=xlDatabase, _
                 SourceData:=Sheets("Data").Range("A1:AD" & lrows))
 
This part...
Code:
SourceData:=Sheets("Data").Range("A1:AD" & lrows)

Can't be range object, but rather string using R1C1 reference. So...
Code:
SourceData:="Data!R1C1:R" & lrows & "C30"
 
Have tried this but getting same error...

Please Note : I am copying Pivot Table from Another Workbook into new workbook and Then I had changed Pivot Table name in new workbook and then trying to change Source Data but error occurred.

Code:
Dim Pivot_sht As Worksheet
Set Pivot_sht = ThisWorkbook.Sheets("Summary")
Pivot_sht.PivotTables("Manpower").ChangePivotCache _
                 ThisWorkbook.PivotCaches.Create( _
                 SourceType:=xlDatabase, _
                 SourceData:="Data!R1C1:R" & lrows & "C30")
 
Back
Top