Share via

Creating consolidation Pivot Table using VBS

Anonymous
2016-12-07T14:23:24+00:00

I hope some one can help me. I have a workbook that I am copying several worksheets into using VBA and am wanting to update a consolidation Pivot Table from data on each sheet. I have some code I pieced together to create the array that would go after SourceData:= in the following piece of code

Sheets("Pivot Table").Select

ActiveSheet.PivotTableWizard SourceType:=xlConsolidation, SourceData:=Array(Array("'0342'!R1C4:R65C75", "0342"), Array("'0370'!R1C4:R65C75", "0370"),Array("'0411'!R1C4:R65C75", "0411"))

If I leave the array hard coded like above the code will run but if i create a varaiable and assign SheetArray to equal the string that gets created from other code and change SourceData:=SheetArray i get an error. The string that gets created is the same Array as above. The error is Run-Time Error '1004': Cannot open PivotTable Source file 'Array(Array(".xls'0342". I am a total loss what I need to do to correct this.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2017-01-12T06:57:12+00:00

    Hi,

    To address your concern about creating consolidation pivot table using VBS, we suggest that you post your query on Technet Community Forum.

    Regards.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-12-07T15:58:41+00:00

    Is there a specific format for the SourceData on a consolidation Pivot Table.  I have recorded a macro using the wizard and have seen two different formats that gets applied to SoureData

    1: Array(Array("D0342!R1C4:R51C52", "D0342"), Array("D0370!R1C4:R56C52", "D0370"), Array("D0411!R1C4:R42C52", "D0411"))

    2: Array(Array("'D0342'!R1C4:R51C52", "D0342"), Array("'D0370'!R1C4:R56C52", "D0370"), Array("'D0411'!R1C4:R42C52", "D0411"))

    Was this answer helpful?

    0 comments No comments