VBA pivot table - Runtime 5 error on Excel 2013 but not 2016?

bdbly

New Member
Joined
Jan 8, 2018
Messages
11
Hello. I created a vba for my coworkers in Excel 2016. When users in 2013 run the code, they keep getting a runtime 5 error. Any suggestions? I tried various solutions on this board but can't seem to get it to work. Is it the "DefaultVersion:=6" that is creating the problem?

Code:
 Cells.Find(What:="dec 17", After:=ActiveCell, LookIn:=xlFormulas, LookAt _        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "'2017 P&L'!R5C8:R250C10", Version:=6).CreatePivotTable TableDestination:= _
        "'[Entity Template v013118 - 1120.xlsm]2017 P&L'!R5C12", TableName:= _
        "PivotTable3", DefaultVersion:=6
    ActiveWorkbook.ShowPivotTableFieldList = False
    ActiveWorkbook.ShowPivotTableFieldList = True
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Jan - Dec 17"), "Sum of Jan - Dec 17", xlSum
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Categories")
        .Orientation = xlRowField
        .Position = 1
    End With
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
i believe i got an error like this on a .Printsheet
Excel may have removed/added a parameter the other version doesnt use.

Try removing the param to see if it takes it. (sometimes it accepts the default)
 
Last edited:
Upvote 0
try the following changes:
...
Code:
Version:=6
to
Code:
Version:=xlPivotTableVersion15

and
...
Code:
DefaultVersion:=6
to
Code:
DefaultVersion:=xlPivotTableVersion15
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top