简体   繁体   English

使用Excel VBA错误地对数据透视表进行过滤

[英]Pivot Table filter Wrongly Using Excel VBA

I use Record Macro to filter PivotTable "PR to PO Days" field label filter between 0 and 4. When i record, it can filter correctly, only show 1, 2 & 4. But when i run the macro, it is not filter correctly, 24 which is should not show always show. 我使用记录宏在0到4之间过滤数据透视表“ PR to PO Days”字段标签过滤器。当我记录时,它可以正确过滤,只显示1、2和4。但是当我运行宏时,它过滤不正确,不应该显示的24总是显示。 Because later i want to modify the coding the values to filter in between are variable (number key in by users at cells). 因为稍后我想修改编码,所以要在其中过滤的值是可变的(单元格中用户输入的数字)。

Hope anyone can get help. 希望任何人都能得到帮助。 Thank you! 谢谢! 在此处输入图片说明

Remove the quotation marks from "0" and "4", otherwise the filter considers the values as text and not as values . 删除“ 0”和“ 4”中的引号,否则过滤器将值视为文本而不是 In a text comparison, "24" falls between "0" and "4". 在文本比较中,“ 24”介于“ 0”和“ 4”之间。

With ActiveSheet.PivotTables("PivotTableMacro4").PivotFields("PR to PO Days")
    .ClearAllFilters
    .PivotFilters.Add Type:=xlCaptionIsBetween, Value1:=0, Value2:=4
End With

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

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