Recorded VBA - Inserting a Pivot Table

idlewyld89

New Member
Joined
Jun 10, 2018
Messages
23
Alright so I've written 90% of my program by hand, and I figured one part that would be ideal to simply record once all the manual sorting is out of the way would be the Pivot Table formatting. For some reason, I get the following error from the below code:

Runtime Error 5: Invalid Procedure Call or Argument

I use the automated method of adding a pivot table (Insert > Pivot Table) and assumed that would be the least likely to cause problems as Excel is already doing most of the work itself...

The error occurs on the 2nd line.

Code:
Sub RegReport()

    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "REGTable", Version:=6).CreatePivotTable TableDestination:="Sheet32!R3C1", _
        TableName:="PivotTable11", DefaultVersion:=6
    Sheets("Sheet32").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable11").PivotFields("AM")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable11").PivotFields("BM")
        .Orientation = xlRowField
        .Position = 2
    End With
    With ActiveSheet.PivotTables("PivotTable11").PivotFields("Due/Idle Loc")
        .Orientation = xlRowField
        .Position = 3
    End With
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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