Runtime Error 5 - Invalid Procedure Call or Argument

I need help with this macro. Every time I run it I get below error. I thought it was a simple macro that I could use in my team to take less time than they took to manually create this pivot table every time they run the report. However, it doesn't work. See the error below and let us know. I got bolder and made a mistake in italics.

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

      

+3


source to share


1 answer


The answer to your problem is located here .

Your sheet name in TableDestination:="LED OTTR!R1C1"

must be surrounded by single quotes for it to workTableDestination:="'LED OTTR'!R1C1"



You will also have duplicate name problems if you don't delete this pivot table before restarting the code.

+5


source







All Articles