Public Sub Create_Pivot_1()
Worksheets("Raw_Data").Activate
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set Rng = Range("A1:G" & lastrow)
Worksheets.Add
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="Raw_Data!" & Rng.Address).CreatePivotTable TableDestination:=ActiveSheet.Range("A1")
With ActiveSheet.PivotTables(ActiveSheet.PivotTables.Count).PivotFields("Part")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables(ActiveSheet.PivotTables.Count).PivotFields("Type")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables(ActiveSheet.PivotTables.Count).AddDataField ActiveSheet.PivotTables( _
ActiveSheet.PivotTables.Count).PivotFields("QTY"), "Sum of QTY", xlSum
End Sub