简体   繁体   English

计算字段未填充 - Pivot Excel vba

[英]Calculated Field not populating - Pivot Excel vba

Could someone give a short tip why the calculated.field is not being created?有人可以给出一个简短的提示,为什么没有创建计算字段? the two sums show up but no the third.两个总和出现,但没有第三个。

'Insert Data Field
With ActiveSheet.PivotTables("ForwinPivotTable").PivotFields("Gross Profit (EUR)")
.Orientation = xlDataField
.Position = 1
.Function = xlSum
.NumberFormat = "#,##0"
.Name = "GP (Eur) "
End With

'Insert Data Field
With ActiveSheet.PivotTables("ForwinPivotTable").PivotFields("Export Chargeable Weight (kg)")
.Orientation = xlDataField
.Position = 1
.Function = xlSum
.NumberFormat = "#,##0"
.Name = "Total Charg. Weight "
End With

With ActiveSheet.PivotTables("ForwinPivotTable").CalculatedFields
.Add "GP/kg (Eur)", "= 'GP (Eur) '/ 'Total Charg. Weight '"
.PivotFields("GP/kg (Eur)").Orientation = xlDataField
End With
    With ActiveSheet.PivotTables("ForwinPivotTable")
    .CalculatedFields.Add "GP/kg (Eur)", "= 'Gross Profit (EUR)'/ 'Export Chargeable Weight (kg)'"
    .PivotFields("GP/kg (Eur)").Orientation = xlDataField
    End With

Mistake I had made was referencing the fields not by source title but by title in the pivot table.我犯的错误是不是按源标题而是按 pivot 表中的标题引用字段。

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

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