使用多个条件的VBA自动筛选 [英] VBA Autofilter Using Multiple Criteria

查看:1350
本文介绍了使用多个条件的VBA自动筛选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

我正在尝试根据VBA中的多个条件进行过滤.

但是我找不到一种简单的方法.我选择的条件将始终是恒定的,但大于2,因此我不能使用or运算符.

下面的代码;

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

我当前的解决方案仅对数组中的最后一个条件进行过滤.

由于文件设置,我无法在另一列中插入公式.

谢谢

解决方案

您需要Operator:= xlFilterValues.

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

如果标准是恒定的,我将假定过滤器范围也是一致的.您可能希望在不久的将来不再使用Selection.请参阅如何避免在Excel VBA中使用选择" .

All,

I am trying to filter on multiple criteria within 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.

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.

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. See How to avoid using Select in Excel VBA.

这篇关于使用多个条件的VBA自动筛选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆