Macro Error for Pivot Table

Occasional Contributor

I can create a Pivot Table for the data I download and it works fine.

However, when I made a Macro to do the same thing, I get an error. The error is: Run-time error '5':


The following is a screenshot of the highlighted error in the Macro. I am now using Excel 2013, however I made an initial Macro using an older version of Excel and am now trying to make a pivot table using 2013 and installing it near the start of the existing Macro I have.

Macro Error for Pivot TableMacro Error for Pivot Table

How do I correct for this error?

7 Replies

@WayneEK Does "Table1" exist? And what about the destination "Contract1 Report"?


If either one of those doesn't exist, or is even spelled differently, then that would cause the code to bug.

Thanks for replying. I confirmed the spelling and reference to the sheet and table is correct but am still getting the error. The only thing I can think it might be is that I should create a separate Sheet to put the Pivot Table on, instead of the existing sheet that the table is on. Thanks anyways.

@WayneEK try recording a new macro to create the pivot table then compare both codes

@WayneEK did you ever resolve this?  I am getting a very similar message and it is indicating the bug is within the pivot portion.  I built the macro using the record macro feature and not the line by line code.  Any advice?


I ran into this same issue. In Excel 2013, the PivotTable version number is different than if you are using other versions.


When using Excel 2013, you must change Version:=6 to Version:=xlPivotTableVersion15. Change DefaultVersion:=6 to DefaultVersion:=xlPivotTableVersion15.


Excel 2013 VBA script for creating PivotTable:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Data!R1C1:R4000C6", Version:=xlPivotTableVersion15).CreatePivotTable TableDestination:= _
"Template!R3C1", TableName:="SalesTaxTable", DefaultVersion:=xlPivotTableVersion15



I am running into same error in Microsoft 365. Was there ever a fix?


I am currently trying to run a macro that I made which contains that step, even after converting the macro over into the personal folder, I am unable to run that macro on my co-worker's computers. Is there some tip anyone can give me to share macros seemlessly?