在同一字段上使用通配符的空格和数字的多重过滤条件不起作用

尽pipe关于这个话题的问题很多,但我还是无法find解决我的问题的scheme(这可能也可能不是我的错)。

我需要自动筛选范围以返回空格和614开始的数字。

此列已使用以下格式预先格式化:

Range("B:C").NumberFormat = "###0" 

这是为了移除Excel想要在某些数字上使用的科学记数法格式。

然后我使用以下来应用filter:

 With ActiveSheet .AutoFilterMode = False 'remove any active filters .Range("A1:O1").AutoFilter Field:=2, Criteria1:="614*", Operator:=xlOr, Criteria2:="=" End With 

不pipe我如何应用filter,包括使用数组,filter只返回空白值。 我也使用了Criteria1:=“= 614 *”来获得相同的结果。

我唯一能确定的是这个数字是以614开始的,并且会有以下几种组合。

数据types是否存在问题? 空白是string,数字是数字? 只有一个博客稍微解决了这个问题,似乎表明我不能在这种情况下使用通配符。 它是否正确?

基本上这些数字是澳大利亚移动号码,因此有11个字符的长度,只有前3个是一个常数。 这就是为什么我真的想使用通配符来查找这些logging。 我需要消除这些加上数据集的空白。 根据你的回答以及我在很大程度上开始意识到的事情,我唯一的select就是把这些数字转换成string,如果我想把它作为一个一步的过程。 这会影响后面的代码。 我假设这不能作为autofilter标准的一部分(一厢情愿的想法)?

任何时候,如果遇到对Range.AutoFilter方法的限制 ,只需使用VBA的文本,数字和/或date操作构build匹配标准的字典,并将字典的键作为数组应用于AutoFilter操作。

 Sub wildcard_Number_Filter() Dim a As Long, aTMPs As Variant, dVALs As Object Set dVALs = CreateObject("Scripting.Dictionary") dVALs.CompareMode = vbTextCompare With Worksheets("Sheet1") If .AutoFilterMode Then .AutoFilterMode = False With .Cells(1, 1).CurrentRegion 'build a dictionary so the keys can be used as the array filter aTMPs = .Columns(2).Cells.Value2 For a = LBound(aTMPs, 1) + 1 To UBound(aTMPs, 1) Select Case True Case Not CBool(Len(aTMPs(a, 1))) dVALs.Item(Chr(61)) = Chr(61) 'blanks Case CStr(aTMPs(a, 1)) Like "614*" 'The set of numbers have to be strings in the array If Not dVALs.Exists(aTMPs(a, 1)) Then _ dVALs.Add Key:=CStr(aTMPs(a, 1)), Item:=aTMPs(a, 1) Case Else 'no match. do nothing End Select Next a 'test the array 'Dim k As Variant 'For Each k In dVALs.Keys ' Debug.Print k & " - " & dVALs.Item(k) 'Next k 'filter on column B if dictionary keys exist If CBool(dVALs.Count) Then _ .AutoFilter Field:=2, Criteria1:=dVALs.Keys, _ Operator:=xlFilterValues, VisibleDropDown:=False 'data is filtered on 614* and blanks (column B) 'Perform work on filtered data here End With If .AutoFilterMode Then .AutoFilterMode = False End With dVALs.RemoveAll: Set dVALs = Nothing End Sub 

通过使用此方法,您可以对值执行任何操作,以通过标准VBA方法检查它们是否包含或排除,可以生成一个有效数组作为filter集。 通过将工作表中的值批量加载到variables数组中,读取和评估单个单元格的时间几乎不存在。

number_Wildcards_Filter_before
在构build和应用filter之前

number_Wildcards_Filter_after
应用filter后

考虑在每个数据中添加'。

 Example : 100 => '100