Auto filter with multiple wildcards

前端 未结 2 2028
情书的邮戳
情书的邮戳 2021-01-24 07:49

Is there a way to use an Excel auto filter, whereby you set a predefined list of values to filter by, and it will return all the cells in a column that contain that phrase? For

2条回答
  •  一向
    一向 (楼主)
    2021-01-24 08:31

    You cannot filter more than two criteria with wildcards. The nature of your sample data is such that you would be using ="Brian*", ="Mark*" or ="*John" to wildcard the first names as either Begins with... or Ends with... criteria. You can only use two of these in any one filter operation. You cannot add a third by creating an array of wildcarded values.

    This works:

    with activesheet.cells(1, 1).currentregion
        .AutoFilter Field:=1, Criteria1:="=Brian*", Operator:=xlOr, Criteria2:="=*John"
    end with
    

    This does not work:

    with activesheet.cells(1, 1).currentregion
        .AutoFilter Field:=1, Criteria1:=Array("Brian*", "Mark*", "*John"), Operator:=xlFilterValues
    end with
    

提交回复
热议问题