[英]Value Field not Displaying Values when using VBA to make a pivot table
該代碼不會導致錯誤,並且將創建具有正確的行和列字段的表。 但是,值字段中什么也沒有出現。
'Insert Row Fields
With ActiveSheet.PivotTables("Rev by Facility")
With .PivotFields("Facility")
.Orientation = xlRowField
.Position = 1
End With
'Insert Column Fields
With .PivotFields("Revenue")
.Orientation = xlColumnField
.Position = 1
End With
'Insert Data Field
With .PivotFields("SubTotal 2")
.Orientation = xlValuesField
.Position = 1
.Function = xlSum
.Name = "Sum of SubTotal 2"
End With
End With
這只是代碼的一部分,上面的代碼不應導致value字段不出現。 數據透視表的數據源包括該列以及我要顯示在value字段中的所有數據。
線條縮進不正確會導致各種問題。 嘗試這個
'Insert Row Fields
With ActiveSheet.PivotTables("Rev by Facility")
With .PivotFields("Facility")
.Orientation = xlRowField
.Position = 1
End With
'Insert Column Fields
With .PivotFields("Revenue")
.Orientation = xlColumnField
.Position = 1
End With
'Insert Data Field
With .PivotFields("SubTotal 2")
.Orientation = xlValuesField
.Position = 1
.Function = xlSum
.Name = "Sum of SubTotal 2"
End With
End With
要將樞軸字段定義為“值字段”,必須使用xlDataField
。
.Orientation = xlDataField
以防萬一:
通常稱為“過濾器字段”的方向為xlPageField
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.