我在 Excel 中有一个数据透视表,如下所示:
Account e-mail Sum of Price Sum of Billing Price
Customer Z blah@gmail.com 30 33.75
Customer Z Total 30 33.75
Customer Y blah@gmail.com 10 10.5
Customer Y Total 10 10.5
Grand Total 40 44.25
我有以下 VBA 代码:
For j = 2 To pt.RowFields(1).PivotItems.Count
Sheets("Configuration").Range("j2").Value = Sheets("Configuration").Range("j2").Value + 1
Client = pt.RowFields("Account").PivotItems(j)
sum = pt.GetPivotData("Sum Of Billing Price", "Account", Client)
net = pt.GetPivotData("Sum Of Price", "Account", Client)
email = pt.RowFields("e-mail").PivotItems(j)
...
当我运行代码时,我收到错误:Unable To Get PivotItems Property Of PivotField Class
将值分配给电子邮件时。将值分配给 Client 按预期工作。我也尝试过使用索引号,结果相同。