【问题标题】:How do I search for a wildcard number in VBA?如何在 VBA 中搜索通配符号码?
【发布时间】:2015-01-29 05:49:40
【问题描述】:

我想在我的 Excel 工作表中搜索以单个数字、句点和空格开头的任何字符串,但这不起作用:

Cells.Find(What:="[0-9]. ", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Select

运行时错误 91 - 对象变量或未设置块变量。

【问题讨论】:

    标签: excel vba wildcard


    【解决方案1】:

    .Find不允许使用这样的搜索,使用这个方法:

    Sub test()
    Dim ocell As Range, Result$
    For Each ocell In ActiveSheet.UsedRange
        If ocell.Value Like "[0-9. ]*" Then
            Result = Result & ocell.Address & Chr(10)
        End If
    Next
    MsgBox Result
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 2018-06-10
      • 2020-04-26
      • 2022-08-02
      • 1970-01-01
      相关资源
      最近更新 更多