简体   繁体   English

使用多个标准的VBA自动过滤器

[英]VBA Autofilter Using Multiple Criteria

All, 所有,

I am trying to filter on multiple criteria within VBA. 我试图在VBA中过滤多个条件。

However I cannot find a simple way of doing this. 但是我找不到这样做的简单方法。 The criteria I am selecting will always be constant but greater than 2 therefore I cannot use the or operator. 我选择的标准总是不变但大于2,因此我不能使用或运算符。

Code below; 代码如下;

Selection.AutoFilter field:=10, Criteria1:=Array("Fixtures & Fittings", "Furniture & Equipment", "Land & Buildings", "Motor Vehicles", "Plant & Machinery")

My current solution only filters on the last criteria within the array. 我当前的解决方案仅过滤数组中的最后一个条件。

Due to the file set up I am unable to insert a formula in another column. 由于文件设置,我无法在另一列中插入公式。

Thanks 谢谢

You need Operator:=xlFilterValues. 你需要Operator:= xlFilterValues。

Selection.AutoFilter field:=10, Operator:=xlFilterValues, Criteria1:=Array("Fixtures & Fittings", "Furniture & Equipment", "Land & Buildings", "Motor Vehicles", "Plant & Machinery")

If the criteria is constant, I would assume that the filter range is consistent as well. 如果标准是恒定的,我会假设过滤器范围也是一致的。 You may wish to move away from using Selection in the near future. 您可能希望在不久的将来不再使用Selection。 See How to avoid using Select in Excel VBA . 请参见如何避免在Excel VBA中使用“选择”

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

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