Okay, I have sifted through tons of posts and cannot get my code to run. I am trying to create a reconciliation report, which I have running just fine. The problem comes when I am trying to take each month's report and paste it into a master reconciliation file. I have everything working perfectly, except I cannot for the life of me figure out WHY my pivot table source won't change.
The error I am getting with the code as is:
Run-time error '1004': Application-defined or object-defined error
Any suggestions? :-\
Dim SrcData As StringDim PivTbl As PivotTableSrcData = ActiveSheet.Name & "!" & Range("$A$1:$H$" & LastRow).Address(ReferenceStyle:=xlR1C1)On Error Resume NextSet PivTbl = Sheets("Report").PivotTables("ReportPivot")On Error GoTo 0If PivTbl Is Nothing Then'create pivotElseActiveWorkbook.PivotTables(PivTbl).ChangePivotCache ActiveWorkbook. _PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SrcData, _Version:=xlPivotTableVersion15)PivTbl.RefreshTableEnd If推荐答案Since the problem is here:
ActiveWorkbook.PivotTables(PivTbl).ChangePivotCache ActiveWorkbook. _PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SrcData, _Version:=xlPivotTableVersion15)I guess you cannot get a pivot table passing the table itself as argument: .PivotTables(PivTbl)
PivTbl is already the table you want.
PivTbl.ChangePivotCache.......