Share via

ActiveWorkbook.PivotCaches.Create

Anonymous
2012-03-07T07:44:59+00:00

I try to record macro with pivot table in Ms. Excel 2010.  

After record, and when I try to run the recorded macro, it failed in the first statement (see below):

Please advise what is wrong to this macro recording.

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

"YYYYMM Billing!R1C1:R500C47", Version:=xlPivotTableVersion10). _

CreatePivotTable TableDestination:="Pivot Billing!R2C2", TableName:= _

"PivotTable2", DefaultVersion:=xlPivotTableVersion10

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

Answer accepted by question author

HansV 462.6K Reputation points
2012-03-07T10:23:41+00:00

Sheet names with spaces should be enclosed in single quotes:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

    "'YYYYMM Billing'!R1C1:R500C47", Version:=xlPivotTableVersion10). _

    CreatePivotTable TableDestination:="'Pivot Billing'!R2C2", TableName:= _

    "PivotTable2", DefaultVersion:=xlPivotTableVersion10

Was this answer helpful?

4 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful