vba 如何在excel 2010中编辑宏以使过滤条件为:不等于空白?

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

How to edit a macro in excel 2010 so that the filter criteria is: not equal to blanks?

excelvbaexcel-vba

提问by new2code

I'm new to creating macros so my apologies if my question is not very clear. I have recorded a macro do autofilter a spreadsheet. What I need it to do is to not include the blanks in the filter. Considering that each sheet has different values inputted the way the macro is setup right now is based on the first sheet I used. This is what the code looks like:

我是创建宏的新手,所以如果我的问题不是很清楚,我很抱歉。我已经录制了一个宏来自动过滤电子表格。我需要它做的是不要在过滤器中包含空白。考虑到每个工作表都有不同的输入值,现在宏设置的方式基于我使用的第一张工作表。这是代码的样子:

Range ("B7:B8) .Select
Selection.AutoFilter
ActiveSheet.Range("$B:$N").AutoFilter Field:=12, Criteria1:=Array( _
    "1.00", "13.00", "2.00", "3.00", "3.50", "42.50", "6.00", "7.00", "Total"), Operator _
    :=xlFilterValues

So what I think it should be is changing the Criteria in order for it to not select blanks instead of selecting exact values (that will be different in every sheet).

所以我认为应该改变标准,以便它不选择空白而不是选择确切的值(每张纸都不同)。

Does anyone know how to do this? and please let me know if you need any other information.

有谁知道如何做到这一点?如果您需要任何其他信息,请告诉我。

Thank you.

谢谢你。

回答by Siddharth Rout

How to edit a macro in excel 2010 so that the filter criteria is: not equal to blanks?

如何在excel 2010中编辑宏以使过滤条件为:不等于空白?

in continuation to my comment, what if the value is <0?

继续我的评论,如果值 <0 怎么办?

The best way is to use this

最好的方法是使用这个

Criteria1:="<>"

FOLLOWUP FROM COMMENTS

来自评论的跟进

Try this

尝试这个

Yourrng.AutoFilter Field:=12, Criteria1:="<>", Criteria2:="<>-"

Yourrng.AutoFilter Field:=12, Criteria1:="<>", Criteria2:="<>-"

I did this

我做了这个

Myrng.AutoFilter Field:=12, Criteria1:="<>", Criteria2:="<>0"

回答by user2140261

For number you can use:

对于数字,您可以使用:

Criteria1:=">0"

For Text you could use:

对于文本,您可以使用:

Criteria1:="=*"