|
录制的宏代码如下:
Sub Macro1()
Cells.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"BoM!C1:C5").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1")
.NullString = "0"
.SmallGrid = False
End With
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:= _
"Component number", ColumnFields:="List"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Qty (CUn)")
.Orientation = xlDataField
.Caption = "Sum of Qty (CUn)"
.Function = xlSum
End With
End Sub
然后把这个Pivot删掉之后,用VBA想跑出一个一样的Pivot,结果提示AddFields method of PivotTable class failed.
提示一下代码有问题
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:= _
"Component number", ColumnFields:="List"
球高手帮忙解答! |
|