vba 使用带标准的自动过滤器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10657597/
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
Using AutoFilter with Criteria
提问by Andy5
I have hit a brick wall on this one, but I would like someone who can help me with autofilter and perhaps advanced filter (but not sure on this one) where I have one column that contains dates which also contains the value 'NULL' and another column that contains numbers plus the value 'NULL'. In this second column there can be duplicate numbers.
我在这个问题上遇到了一堵砖墙,但我希望有人可以帮助我进行自动过滤器和高级过滤器(但不确定这一点),其中我有一列包含日期,其中还包含值“NULL”和包含数字加上值“NULL”的另一列。在第二列中可能有重复的数字。
My criteria for the first column is to exclude the value 'NULL', but to also exclude dates less than 14. The criteria for the second column is to include ALL 'NULL' values, but where there are numbers ONLY to show unique numbers (or distinct in proper speak).
我对第一列的标准是排除值“NULL”,但也要排除小于 14 的日期。第二列的标准是包括所有“NULL”值,但其中的数字仅用于显示唯一数字(或用正确的语言区分)。
I am unsure how to do this and I haven't been able to find anything on the internet.
我不确定如何执行此操作,并且我无法在互联网上找到任何内容。
Can anyone help?
任何人都可以帮忙吗?
采纳答案by Scott Holtzman
I used the macro recorder to get this code:
我使用宏记录器来获取此代码:
ActiveSheet.Range("$A:$B").AutoFilter Field:=2, Criteria1:="<>NULL", _
Operator:=xlAnd, Criteria2:="<5/14/2012"
That said, you will need to do this:
也就是说,你需要这样做:
ActiveSheet.Range("$A:$B").AutoFilter Field:=2, Criteria1:="<>NULL", _
Operator:=xlAnd, Criteria2:="<" & Date - 14
For the 2nd filter. Copy the column to a blank column and use the RemoveDuplicates function to get the Distinct List of numbers.
对于第二个过滤器。将该列复制到空白列并使用 RemoveDuplicates 函数获取不同的数字列表。
Intersect(UsedRange, Range("A1")).EntireColumn.Copy Range("Z1")
Intersect(UsedRange, Range("Z1")).EntireColumn.RemoveDuplicates(more args here that you will need to fill)