我想创建一个如下所示的数据透视表:
我查看了Microsoft,它只教我如何为[SKU船舶数量总和]创建一列:
ActiveWorkbook.ActiveSheet.Select
Range("A1").Select
Set objTable = Sheet1.PivotTableWizard
Set objField = objTable.PivotFields("Deal ID & SKU")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("SKU Ship quantity")
objField.Orientation = xlDataField
但是这只为SKU Ship数量创建了一列,当我尝试使用相同的脚本添加[GROSS SELL TO(LC)]时,数据透视表就会失真。 我有几列要添加。我怎么能实现这个目标?
感谢。
答案 0 :(得分:0)
试试这个:
ActiveWorkbook.ActiveSheet.Select
Range("A1").Select
Set objTable = Sheet1.PivotTableWizard(TableDestination:=Sheets.Add.Range("A3"))
With objTable
.PivotFields("Deal ID & SKU").Orientation = xlRowField
.PivotFields("SKU Ship quantity").Orientation = xlDataField
.PivotFields("GROSS SELL TO (LC)").Orientation = xlDataField
With .DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
End With