Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Time Error 5 - Invalid Procedure Call or Argument

I need help with this macro. Every time I run it, I get the error below. I thought it was a simple macro that I could have anybody on my team use to make it take a less time than they were taking to manually create this PivotTable every time they ran the report. However, it's not working. Please see error below and advise. I emboldened and italicized the error.

Error

Sub LEDOTTR()
'
' LEDOTTR Macro
'

'
    Range("A87").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    ***ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R87C1:R8214C25", Version:=xlPivotTableVersion14).CreatePivotTable _
        TableDestination:="LED OTTR!R1C1", TableName:="PivotTable6", _
        DefaultVersion:=xlPivotTableVersion14***
    Sheets("LED OTTR").Select
    Cells(1, 1).Select
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("LED")
        .Orientation = xlPageField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("Hierarchy name")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable6").PivotFields("LED").CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("LED")
        .PivotItems("LED Marine").Visible = False
        .PivotItems("LL48 Linear LED").Visible = False
        .PivotItems("Other").Visible = False
    End With
    ActiveSheet.PivotTables("PivotTable6").PivotFields("LED"). _
        EnableMultiplePageItems = True
    ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _
        "PivotTable6").PivotFields("   Late " & Chr(10) & "Indicator"), "Sum of    Late " & Chr(10) & "Indicator", _
        xlSum
    ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _
        "PivotTable6").PivotFields("Early /Ontime" & Chr(10) & "   Indicator"), _
        "Sum of Early /Ontime" & Chr(10) & "   Indicator", xlSum
End Sub
like image 763
user3067028 Avatar asked May 29 '15 20:05

user3067028


People also ask

What does runtime error 5 mean?

"Run-time error '5': Invalid procedure call or argument"This error occurs when trying to change the location of the sysdata directory to a shared directory on the network from the Change SYSDATA Directory dialog box of Microsoft FRx.

What does invalid procedure call or argument mean?

As Microsoft says, an Invalid Procedure Call Or Argument (Error 5) occurs when you have a specified value that is out of the range of the argument or you are using a procedure that is not available in the current Excel platform. The error could be one of these problems that can cause by different reasons.

What is run-time error in VBA?

Runtime errors are often caused by unexpected data being passed to the VBA code, mismatching data types, dividing by unexpected zeros, and defined cell ranges not being available. Runtime errors are also the most varied and complex to track down and fix.


1 Answers

The answer to your problem is located here.

Your sheet name in TableDestination:="LED OTTR!R1C1" needs to be surrounded with single quotes in order for it to work TableDestination:="'LED OTTR'!R1C1"

You will also have problems with the duplicated name if you do not delete this PivotTable before rerunning the code.

like image 136
Byron Wall Avatar answered Oct 13 '22 03:10

Byron Wall