[英]How to sum the pivot item data based on condition using Excel VBA
ParentName Designation offsite onsite total ASP ASE 1 1 SE 2 2 4 ITA 3 7 10 AssSE **2** 2 4 ASP Total 8 11 19 ESP ITA 15 15 AssC 2 2 AssSE 1 1 ESP Total 18 18 IS-TP ASE 7 7 AssSE **19** 19 SE 32 32 BA 1 3 4 ITA 24 11 35 IS-TP Total 83 14 97 Grand Total 109 25 134
In that pivot table the star marked cell values can be summed based on the pivot data. 在该数据透视表中,可以根据数据透视表对星号标记的单元格值求和。 How to get the pivot data and sum the values based on the designation.
如何获取数据并根据指定的值求和。 ie if designation is Asst.system engineer and Parent IOU Name is "Is-Telecom-parent" and Assurance Services-1Parent then get the offsite total count and summed them as resultant in excel using VBA.
例如,如果指定是Asst.system工程师,并且父IOU名称是“ Is-Telecom-parent”,并且Assurance Services-1Parent,则获得异地总数,并使用VBA将它们汇总为excel。
**Provide VBA code **提供VBA代码
Try this code: 试试这个代码:
Sub SumSelectedPivotElements()
Dim piv As PivotTable
Dim res As Double
Set piv = Sheets("YourSheet").PivotTables(1) 'Replace with correct sheetname
'Replace "Location" with your column field name
res = piv.GetPivotData("Name of your data field", "ParentName", "IS-TP", "Designation", "AssSE", "Location", "offsite")
res = res + piv.GetPivotData("Name of your data field", "ParentName", "IS-TP", "Designation", "AssSE", "Location", "offsite")
Debug.Print "The result is: ", res
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.