我使用的是Excel 2010,我使用以下VBA代码创建数据透视表: -
Sub addFields()
With ActiveSheet.PivotTables(1)
With .PivotFields("Name")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Location")
.Orientation = xlPageField
.Position = 1
End With
.AddDataField ActiveSheet.PivotTables(1).PivotFields("Order Amount"), _
"Sum of Amount", xlSum
End With
End Sub
以下是我想要创建数据透视表的 Sheet1 上的数据。
Name Order Amount Location
Grace 1200000 New York
Tom 2000000 New York
Madhuri 5000000 Delhi
Hari 6000000 Delhi
Raj 7000000 Delhi
Victoria 8000000 New York
但我得到了一个:
运行时错误1004:无法获取Worksheet类的PivotTables属性。
有人可以就此提出建议吗?