为什么这个 VBA 查找函数找不到搜索字符串?

问题描述 投票:0回答:2

我在 Excel 中使用 VBA,我试图在单元格中查找不带引号的文本“Summary”。该单元格位于第一列中,我想找到它位于哪一行。我知道它在那里,当我查看工作簿时我看到它。但是,我的条件“如果未找到则什么都没有”不会执行,这意味着未找到该值。我的发现有什么问题,我该如何解决这个问题。谢谢。

Sub RemoveFooterRows(theFile)
Dim found As Range
Set found = Workbooks(theFile).Worksheets(1).Columns(1).Find _
    ("Summary", , xlValues, xlPart, xlByRows, xlNext, False, , False)


If Not found Is Nothing Then
    MsgBox ("val is inif " & found.Row)
 '   Workbooks(theFile).Close
End If

End Sub
excel vba find
2个回答
0
投票
Public Sub RemoveFooterRows(theFile)

    Dim res As Variant, ws As Worksheet

    On Error Resume Next
    For Each ws In Workbooks(theFile).Worksheets

        res = Application.WorksheetFunction.Match("Summary", ws.Range("A:A"), 0)
        If IsEmpty(res) = False Then
            MsgBox "Val is inif " & res
            GoTo Skip
        End If

    Next ws
    On Error GoTo 0

End Sub

0
投票

我有同样的问题,无法在Excel VBA宏代码编辑中使用查找和替换功能,当我在Window 10设置中删除第二语言设置“英语(美国)美国键盘”后,查找和替换功能恢复如前。

© www.soinside.com 2019 - 2024. All rights reserved.