Macro to Create Pivot

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have data that is copied to a sheet called "Overaged Inventory") using a macro which copied the data perfectly

once I copied would like a macro set up to create a pivot table in cell M1 onwards


However when running the code, I get invalid procedure or call and rghe code below is highlighted

]code] ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Overaged Inventory!R1C1:R1048576C10", Version:=6).CreatePivotTable _
TableDestination:="Overaged Inventory!R1C13", TableName:="PivotTable4", _
DefaultVersion:=6 [/code]



see full code


Code:
 Sub Create_Pivot()

    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Demo Overaged Stock!R1C1:R1048576C10", Version:=6).CreatePivotTable _
        TableDestination:="Overaged inventory!R1C13", TableName:="PivotTable8", _
        DefaultVersion:=6
    Sheets("Overaged Inventory").Select
    Cells(1, 13).Select
    ActiveWorkbook.ShowPivotTableFieldList = True
    With ActiveSheet.PivotTables("PivotTable8").PivotFields("Division")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
        "PivotTable8").PivotFields("Value"), "No. of items", _
        xlCount
    ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
        "PivotTable8").PivotFields("Stand In Value"), "Count of Stand In Value2", _
        xlCount
    With ActiveSheet.PivotTables("PivotTable8").PivotFields( _
        "Count of Stand In Value")
        .Caption = "Sum Value"
        .Function = xlSum
    End With
      With ActiveSheet.PivotTables("PivotTable8").PivotFields("Division")
        .PivotItems("(blank)").Visible = False
    End With
    Range("M1").Select
    ActiveWorkbook.ShowPivotTableFieldList = False
    ActiveSheet.PivotTables("PivotTable8").CompactLayoutRowHeader = "Branch"
    Range("N1").Select
    ActiveSheet.PivotTables("PivotTable8").DataPivotField.PivotItems( _
        "Sum Value").Caption = "Value "
    Range("O1").Select
    ActiveSheet.PivotTables("PivotTable8").PivotFields("Count Value2"). _
        Caption = "No. of Units "
    Range("N2:O15").Select
    Selection.NumberFormat = "#,##0.00"
    Range("O5").Select
End Sub


it would be appreciated if someone could kindly assist me
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

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