vba 过滤以排除公式和空白

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27916104/
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-12 05:49:16  来源:igfitidea点击:

Filter to exclude formula and blank

vbafilter

提问by kobebryant

Filter field has many numbers, formula (result is "-") and blank.
How to write a VBA code to filter all numbers and exclude "-" and blank.
"-" is not text or string it's the result of a formula.

过滤字段有很多数字、公式(结果是“-”)和空白。
如何编写 VBA 代码来过滤所有数字并排除“-”和空白。
“-”不是文本或字符串,它是公式的结果。

On Error Resume Next
ActiveSheet.ShowAllData
Range("G8").AutoFilter Filed:=7,  Criteria2:="=" 
Range("N8").AutoFilter Field:=14, Criteria1:="<>-", _
    Operator:=xlAnd, Criteria2:="<>"

回答by L42

Try this:

尝试这个:

Edit1:For your example, it should be:

Edit1:对于您的示例,它应该是:

Range("N8").AutoFilter Field:=1, Criteria1:="<>-" _
    , Criteria2:="<>", Operator:=xlAnd

This will filter out blanks and cells with -as a result of formula.
Take note that you're only working one Cell N8 which only have 1 field of data.

这将-根据公式过滤掉空白和单元格。
请注意,您只使用一个只有 1 个数据字段的 Cell N8。

Edit2:Another way to make it work is to explicitly define the range you're working on.

Edit2:另一种使其工作的方法是明确定义您正在处理的范围。

Dim r As Range
Set r = Sheets("Sheet1").Range("A1:N100") 'change to suit
r.AutoFilter Field:=14, Criteria1:="<>-" _
    , Criteria2:="<>", Operator:=xlAnd

Is this what you're trying? HTH.

这是你正在尝试的吗?哈。