开发者

Combine multiple exclusion (<>) criteria in AutoFilter

开发者 https://www.devze.com 2023-04-10 16:23 出处:网络
I have worked around my issue by using this dirty hack: \' Filter managerial functions ActiveSheet.Range(\"$A$1:$BW$2211\").AutoFilter Field:=36, Criteria1:=\"<>Head*\", _

I have worked around my issue by using this dirty hack:

    ' Filter managerial functions
    ActiveSheet.Range("$A$1:$BW$2211").AutoFilter Field:=36, Criteria1:="<>Head*", _
    Criteria2:="<>IT*", Operator:=XlAutoFilterOperator开发者_运维问答.xlAnd
    ActiveSheet.Range("$A$1:$BW$2211").AutoFilter Field:=36, Criteria1:="<>Local Head*", _
    Criteria2:="<>Resp*", Operator:=XlAutoFilterOperator.xlAnd
    ActiveSheet.Range("$A$1:$BW$2211").AutoFilter Field:=36, Criteria1:="<>Team Lead*", _
    Criteria2:="<>XB*", Operator:=XlAutoFilterOperator.xlAnd

Is there any way to combine these 3 statements into one line? Excel seems to have a problem as soon as I have a third criteria (Criteria3) in one line. Furthermore, <>Array() seems not to be supported.


An advanced filter might be more suitable for this purpose.

You could also do something like this:

Dim bUnion As Boolean
Dim i As Long
Dim vData As Variant
Dim rDataHide As Range

vData = Application.Transpose(ActiveSheet.Range("$AJ$1:$AJ$2211"))
bUnion = False

For i = 1 To 2211
  If LenB(vData(i)) Then
    If vData(i) Like Whatever Or vData(i) Like Whatever2 Then
      If bUnion Then
        Set rDataHide = Union(rDataHide, ActiveSheet.Range("$AJ$" & i))
      Else
        Set rDataHide = ActiveSheet.Range("$AJ$" & i)
        bUnion = True
      End If
    End If
  End If
Next i
rDataHide.Rows.Hidden = True

You could even use RegEx, I haven't really used RegEx much before though so you would have to google it.

0

精彩评论

暂无评论...
验证码 换一张
取 消