vba Excel 中的高级筛选器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10434038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:00:52  来源:igfitidea点击:

Advanced filter in Excel

excelvba

提问by Paul

I am trying to write an advanced filter in excel. The two conditions to be satisfied are in cells g2 and h2. The first condition is show all values <=0.01and the second condition is show all values <20. I have the following VBA code

我正在尝试在 excel 中编写一个高级过滤器。要满足的两个条件在单元格 g2 和 h2 中。第一个条件是显示所有值<=0.01,第二个条件是显示所有值<20。我有以下 VBA 代码

Sub RefreshAdvancedFilter()
   Range("A6:M5000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
        Range("G1:H2"), Unique:=True
End Sub

Doesn't seem to work. Any ideas?

似乎不起作用。有任何想法吗?

回答by datatoo

If the headers in G1 and H1 are the same and G2 is <=0.01 and H2 is <=20 the only things that will meet BOTH criteria is exactly what you are seeing. Your experience seeing <0.01 and =20 would work however.

如果 G1 和 H1 中的标题相同且 G2 <=0.01 且 H2 <=20,则唯一满足这两个条件的内容正是您所看到的。但是,您看到 <0.01 和 =20 的经验会起作用。

I think this may be a case of AND rather than OR being evaluated for.

我认为这可能是 AND 而不是 OR 被评估的情况。

Try changing your criteria range to G1:G3

尝试将您的标准范围更改为 G1:G3

Include the header in G1, <=0.01 in G2, and <=20 in G3

在 G1 中包含标题,在 G2 中包含 <=0.01,在 G3 中包含 <=20