Background on the issue:
I have a pivot table with data coming from an external source. The external source actually references the same workbook that the pivot table is in. The source data is comprised of three dynamic named ranges on three worksheets. The tables are joined via a SQL statement and then used by the pivot table.
The external source/SQL join method is being used because the multiple consolidation ranges option of building the pivot table is limited and does not provide the level of detail necessary.
The three tables can not be combined into one worksheet.
Now the problem:
The pivot table works correctly. Updates to the source data are reflected in the pivot upon manual refresh. However, I am trying to automatically refresh the pivot using the Worksheet.Activate method with this line of code:
ActiveSheet.PivotTables("ptName").PivotCache.Refresh
(This is the line of code provide by VBA when I recorded the macro using the manual refresh.)
I receive an "Application-Defined or Object-Defined Error" when the sheet is activated. The code also fails when used as a stand-alone macro and not in the Worksheet.Activate method. I can manually refresh and update the pivot but not refresh with VBA.
I think the issue centers around the fact that the external data reference is the same workbook. When the external source is another workbook the automatic refresh works and when the source is a table within the workbook (not external) the automatic refresh works.
Has anyone experienced this problem before and/or have any suggestions on how to workaround the issue?
Thanks.
I have a pivot table with data coming from an external source. The external source actually references the same workbook that the pivot table is in. The source data is comprised of three dynamic named ranges on three worksheets. The tables are joined via a SQL statement and then used by the pivot table.
The external source/SQL join method is being used because the multiple consolidation ranges option of building the pivot table is limited and does not provide the level of detail necessary.
The three tables can not be combined into one worksheet.
Now the problem:
The pivot table works correctly. Updates to the source data are reflected in the pivot upon manual refresh. However, I am trying to automatically refresh the pivot using the Worksheet.Activate method with this line of code:
ActiveSheet.PivotTables("ptName").PivotCache.Refresh
(This is the line of code provide by VBA when I recorded the macro using the manual refresh.)
I receive an "Application-Defined or Object-Defined Error" when the sheet is activated. The code also fails when used as a stand-alone macro and not in the Worksheet.Activate method. I can manually refresh and update the pivot but not refresh with VBA.
I think the issue centers around the fact that the external data reference is the same workbook. When the external source is another workbook the automatic refresh works and when the source is a table within the workbook (not external) the automatic refresh works.
Has anyone experienced this problem before and/or have any suggestions on how to workaround the issue?
Thanks.