可以将“不等于”与“大于或等于”组合使用自动过滤器吗?

时间:2019-02-19 01:06:45

标签: excel vba autofilter

我正在创建一个可以过滤动态列表的工具。

下面的图片是一个示例,

enter image description here

下面的代码可以很好地工作,并且可以选择多个条件。

我遇到的问题是找到一种排除相同精确标准的解决方案。
我尝试了其他版本的数组,范围和AdvancedFilter动作。我可以使它符合一个或两个条件,但不能超过其他条件。另外,我尝试用诸如
之类的方法来调整现有代码 "<>>=010100""<>*>=010100*"

我的问题是:当将“大于或等于”与“小于或等于”结合使用时,是否可以有一个“不等于”运算符?

Sub search_Zones()

Dim myFirstRow As Long
Dim myLastRow As Long
Dim myFirstColumn As Long
Dim myLastColumn As Long
Dim myCriteriaField As Long
Dim myCriteriaField2 As Long
Dim mySale As String
Dim myWorksheet As Worksheet

myFirstRow = 1
myFirstColumn = 1
myCriteriaField = 14
myCriteriaField2 = 13
mySale = "Sales"

Set myWorksheet = wsGADD130

With myWorksheet

     With .Cells
     myLastRow = .Find(What:="*", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
     myLastColumn = .Find(What:="*", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
     End With

            With .Range(.Cells(myFirstRow, myFirstColumn), .Cells(myLastRow, myLastColumn))
                 .AutoFilter Field:=myCriteriaField, Criteria1:=mySale

                With .Range(.Cells(myFirstRow, myFirstColumn), .Cells(myLastRow, myLastColumn))

                     'This is the line i want help with
                     .AutoFilter Field:=myCriteriaField2, Criteria1:=(">=010100"), Operator:=xlAnd, Criteria2:=("<=998876")

                On Error Resume Next

                     'This is where i have another function called upon that extracts the filtered information

                End With

            End With
            .AutoFilterMode = False
        End With

End Sub

0 个答案:

没有答案