[英]Error when accessing pivot table using VBA
我在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
。 將值分配給客戶端按預期方式工作。 我也嘗試過使用索引號,結果相同。
看來您每行都沒有電子郵件。 您可能需要添加條件語句來處理此問題。
原來,此問題是VBA無法處理重復的電子郵件地址。 用一個字符更改一個電子郵件地址,它可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.