Excel自动筛选,其中条件是单元格的值不能包含字母或数字。

huangapple go评论246阅读模式
英文:

excel autofilter where criteria is the cell value must not contain a letter or a number

问题

我有一个范围从A到N,最初我通过H列(字段8)进行筛选,然后我想再次通过N列(字段14)进行筛选,筛选条件是列N中的行不能包含字母或数字,应该如何操作呢?

rng.AutoFilter Field:=8, Criteria1:="Value" ' 通过H列进行筛选
rng.AutoFilter Field:=14, Criteria1:="=*[^0-9A-Za-z]*" ' 通过N列进行筛选,排除包含字母或数字的行
英文:

i have a range A to N, initially i filter it by H(field 8) then I want to filter it again by column N(field 14) with the criteria that the rows in column N must not contain a letter or a number, how would be the way to do that?

rng.AutoFilter Field:=8, Criteria1:="Value" 'Filter by Column H
rng.AutoFilter Field:=14, Criteria1:=       'Filter by Column N

答案1

得分: 2

需要创建另一列并使用此公式进行筛选:

Function hasDigitsOrNumbers(s As String) As String
    Dim ch As String, ln As Long
    Dim i As Long
    
    ln = Len(s)

    For i = 1 To ln
        ch = Mid(s, i, 1)
        If (ch >= "0" And ch <= "9") Or (ch >= "a" And ch <= "z") Or (ch >= "A" And ch <= "Z") Then
            hasDigitsOrNumbers = True
            Exit Function
        End If
    Next
    hasDigitsOrNumbers = False
End Function

=hasDigitsOrNumbers(N1) 并在N1包含数字或字母时返回True,否则返回FALSE。

根据VBasic2008的评论,我编写了一个新的函数,速度大约快2.5倍:

Function hasDigitsOrNumbers(s As String) As String
    hasDigitsOrNumbers = (s Like "*#*") Or (s Like "*[a-z]*") Or (s Like "*[A-Z]*")
End Function
英文:

Have to create another column with this formula and filter this column:

Function hasDigitsOrNumbers(s As String) As String
    Dim ch As String, ln As Long
    Dim i As Long
    
    ln = Len(s)

    For i = 1 To ln
        ch = Mid(s, i, 1)
        If (ch &gt;= &quot;0&quot; And ch &lt;= &quot;9&quot;) Or (ch &gt;= &quot;a&quot; And ch &lt;= &quot;z&quot;) Or (ch &gt;= &quot;A&quot; And ch &lt;= &quot;Z&quot;) Then
            hasDigitsOrNumbers = True
            Exit Function
        End If
    Next
    hasDigitsOrNumbers = False
End Function

=hasDigitsOrNumbers(N1) and returns true if the N1 has digits or letters, otherwise returns FALSE.

Reading VBasic2008's comment I wrote a new function which is about 2.5 times faster:

Function hasDigitsOrNumbers(s As String) As String
    hasDigitsOrNumbers = (s Like &quot;*#*&quot;) Or (s Like &quot;*[a-z]*&quot;) Or (s Like &quot;*[A-Z]*&quot;)
End Function

huangapple
  • 本文由 发表于 2023年3月9日 18:05:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定