【问题标题】:Using wildcards in Excel VBA在 Excel VBA 中使用通配符
【发布时间】:2019-05-01 11:16:05
【问题描述】:

我正在尝试在公式中使用通配符来计算包含文本而不是 "" 的表格列中的单元格

我尝试了以下方法:

  • 字符串比较
Dim g As Integer

g = Application.WorksheetFunction.CountIf(ThisWorkbook.Worksheets("ws1").ListObjects("Table1").ListColumns("ColumnA").DataBodyRange, ""*?"")
  • 使用波浪号失败:
Dim g As Integer

g = Application.WorksheetFunction.CountIf(ThisWorkbook.Worksheets("ws1").ListObjects("Table1").ListColumns("ColumnA").DataBodyRange, ""~*?"")
  • 使用下面的 ASCII 字符返回 0:
g = Application.WorksheetFunction.CountIf(ThisWorkbook.Worksheets("ws1").ListObjects("Table1").ListColumns("Column1").DataBodyRange, Chr(34) & Chr(63) & Chr(42) & Chr(34))

【问题讨论】:

  • 尝试使用"?*"作为标准。
  • "" text 也是 +1 计数吗?
  • 使用 "?*" 而不是 ""?*"" 有效......我认为特殊字符总是必须以某种方式作为前缀,例如分号:Range(Var1 & ":" & Var2)。

标签: excel vba wildcard


【解决方案1】:

久经考验:

Public Function not_qt(ByVal rng As Range) As Integer

    Dim cell As Range
    Dim counter As Integer: counter = 0

    For Each cell In rng
        If Not IsEmpty(cell) Then
            If Not cell Like Chr(34) & "*" & Chr(34) Then
                counter = counter + 1
                'cell.Offset(0, 1) = counter   '<- Only for illustration purposes
            End If
        End If
    Next cell

    not_qt = counter

End Function

【讨论】:

    猜你喜欢
    • 2017-07-02
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 2016-06-02
    • 2014-02-05
    • 1970-01-01
    相关资源
    最近更新 更多