用于过滤特定值的Excel VBA宏 [英] Excel VBA Macro for Filtering Out Specific Value

查看:104
本文介绍了用于过滤特定值的Excel VBA宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要使用宏记录功能,因为我不太了解VBA。我可以稍微看一看,但实际写的不太了解。



我的问题是我想过滤列中的一个特定值,但是记录功能似乎只支持选择特定的值来保持而不是取出。



例如,如果列中填充了预先不知道的任意字,我想确保一个特定的词不在那里。如果一列充满了水果的名字,我想要拿出苹果,而不必知道那里的其他水果的名字。记录功能似乎只是说要保留什么,而不是拿走,所以在这个例子中,我必须选择每一个水果,而苹果才能过滤苹果。



任何帮助将是非常好的,谢谢提前。可能是我只是看不到东西

解决方案

考虑:



<$自动过滤器字段:= 1,条件1:=苹果,$,$ _
运算符:= xlAnd
End Sub

仅作为示例。 / p>

I mostly use the macro record feature since I do not know much about VBA. I can somewhat sight read it, but don't know much about actually writing any.

My problem is that I want to filter out a specific value in a column, but the record feature seems to only support selecting specific values to keep instead of take out.

For example, if the column is filled with arbitrary words not known beforehand, I want to make sure a specific word is not in there. If a column was filled with names of fruits, I would want to take out "apple" without having to know the name of every other fruit in there. The record feature only seems to say what to keep, not what to take away such that in the example, I would have to select every fruit but "apple" in order to filter "apple" out.

Any help would be great, thanks in advance. Could be I'm just not seeing something

解决方案

Consider:

Sub Macro1()
    ActiveSheet.Range("$G$1:$G$21").AutoFilter Field:=1, Criteria1:="<>apple", _
        Operator:=xlAnd
End Sub

just as an example.

这篇关于用于过滤特定值的Excel VBA宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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