(Solved) – Error while trying to create a Pivot Table

(solved)-–-error-while-trying-to-create-a-pivot-table

I’ve been trying to run the following macro to create a pivot table out of a range from another sheet of data and I can´t seem to make it work.

Sub topc()

Application.ScreenUpdating = False

Application.DisplayAlerts = False
Worksheets("TOP C").Delete
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "TOP C"
Application.DisplayAlerts = True



ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Complaints!R1C1:R3000C32", Version:=6).CreatePivotTable _
        TableDestination:="TOP C!R1C1", TableName:="PivotTable1", _
        DefaultVersion:=6


      ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Recurrence")
        .Orientation = xlColumnField
        .Position = 1
    End With

      ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Subtype Name")
        .Orientation = xlRowField
        .Position = 1
    End With

      With ActiveSheet.PivotTables("PivotTable1").PivotFields("Type Inquiry")
        .Orientation = xlPageField
        .Position = 1
    End With

        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Value"), "Sum of Value", xlSum


End Sub

I keep getting error “Invalid Procedure or Argument” in this area:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
       "Complaints!R1C1:R3000C32", Version:=6).CreatePivotTable _
       TableDestination:="TOP C!R1C1", TableName:="PivotTable1", _
       DefaultVersion:=6

and keeps telling me xlDatabase = 1, idk if thats the problem. PLEASE HELP!!

Leave a Reply

Your email address will not be published. Required fields are marked *