is this OK !
Sub nawong() Dim ptquantity As PivotTable Set ptquantity = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "'Sheet1'!A1:I1301").CreatePivotTable(TableDestination:="") ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) ActiveSheet.Cells(3, 1).Select ptquantity.SmallGrid = False With ptquantity.PivotFields("doc number") .Orientation = xlRowField .Position = 1 End With With ptquantity.PivotFields("quantity") .Orientation = xlDataField .Position = 1 .Function = xlSum End With End Sub
|