Results 1 to 6 of 6

VBA to change data source of pivot table to another pivot table

Threaded View

  1. #1
    Registered User
    Join Date
    11-15-2007
    Posts
    9

    VBA to change data source of pivot table to another pivot table

    I'm building an Excel 2007 workbook that contains multiple pivot tables which are all based on same pivot cache. The data source is external and retrieved by a SQL query from an Access 2007 DB. The SQL query may be changed for a purpose so a new pivot cache is created when it's modified.

    I can use Pivot Table Wizard to manually steer all pivot tables to new master copy of pivot table without a problem. But I want to use VBA code to do the process to same time as I have more then 10 pvt in the workbook. So I use the Excel's macro to record a manual change. Below is what is the VBA code produced by Macro:
        Range("E77").Select
        ActiveSheet.PivotTableWizard SourceType:=xlPivotTable, SourceData:= _
            "pvtMstrCopy"
        ActiveWorkbook.ShowPivotTableFieldList = True
    pvtMstrCopy is the name I give to the master pivot table. Cell E77 is inside the target pivot table which I want to change data source.

    But the problem is I can't even re-run this recorded macro. Excel report error message
    Run-time error '1004' PivotTableWizard method of Worksheet class failed
    I add a sheet name to SourceData parameter to "Sheet1!pvtMstrCopy" and it still has the same error.

    It's frustrating since I've been searching same error in various Excel forums for 2 days and I didn't find same one.

    Can anyone tell me how to use VBA to change pivot table data source to another one? Thanks in advance.
    Last edited by huyeote1; 06-13-2011 at 05:38 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1