我有一张看起来像这样的表
Name Order Amount Location
Grace 120000 new jersey
Tom 200000 baltimore
Rick 5000000 hyderabad
Hari 600000 denver
Raj 4000000 Delhi
Victoria 300000 New York
我创建了一个包含所有3个字段的数据透视图,但我无法成功使用 PivotFilters.Add FilterType:= xlValueIsGreaterThan
选项成功...我的代码错了什么?
Sub addFields()
With ActiveSheet.PivotTables(1)
'First row field
With .PivotFields("Name")
.Orientation = xlRowField
.Position = 1
End With
'Report Filter field
With .PivotFields("Location")
.Orientation = xlPageField
.Position = 1
End With
'Order Amount or numerical data in the Values field
.AddDataField ActiveSheet.PivotTables(1).PivotFields("Order Amount"), _
"Sum of Amount", xlSum
End With
With .PivotFields("Sum of Amount").PivotFilters.Add filterType:=xlValueIsGreaterThan DataField :="Sum of Amount" value1:=4000000
End With
End Sub
答案 0 :(得分:0)
测试这个以代替你的最后一个声明
with .PivotFields("Name").PivotFilters.Add2 _
Type:=xlValueIsGreaterThan, DataField:=ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Sum of Order Amount"), Value1:=4000000