简体   繁体   English

使用 vba 获取枢轴值(总计)?

[英]get Pivot Value (Grand Total ) using vba?

I have a Pivot Table and I want a value from that Pivot Table which is the Grand Total value.我有一个数据透视表,我想要该数据透视表中的一个值,即总计值。 If you see the below picture, I want the value "88%".如果你看到下图,我想要值“88%”。 This value is in cell C24 .该值位于单元格 C24 中。 And it is in the Compliance Field (Column C) and the row is the Grand Total.它位于合规性字段(C 列)中,该行是总计。 Above the Pivot Table I already have the filters applied for filtering my data.在数据透视表上方,我已经应用了过滤器来过滤我的数据。 I just want the vba code for this cell/field value.我只想要这个单元格/字段值的 vba 代码。 This is what I tried.这是我尝试过的。

Dim rtot as Double
rtot = Worksheets("ABC").PivotTables("PivotTable2").PivotValueCell(3, 24).Value

在此处输入图片说明

I changed my code using the link in the comments and it worked.我使用评论中的链接更改了我的代码并且它起作用了。 So just sharing it so that its useful for other people.所以只是分享它,以便对其他人有用。

Set pt = Worksheets("ABC").PivotTables("PivotTable2")
            rtot = pt.DataBodyRange.Cells(pt.DataBodyRange.Cells.Count).Value

You could use Evaluate on the Getpivotdata formula:您可以在 Getpivotdata 公式上使用 Evaluate:

rtot = Application.Evaluate("=GETPIVOTDATA(""COMPLIANCE %"",ABC!$A$13)")

Change cell address and sheet to yours (topleftcell of pivot)将单元格地址和工作表更改为您的(枢轴的topleftcell)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM