Forum Discussion
WayneEK
Nov 25, 2019Copper Contributor
Macro Error for Pivot Table
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 scre...
bsand210801
May 18, 2021Copper Contributor
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
RichardSeeley
Dec 02, 2021Copper Contributor