Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA.find命令不适用于我_Excel_Find_Vba - Fatal编程技术网

Excel VBA.find命令不适用于我

Excel VBA.find命令不适用于我,excel,find,vba,Excel,Find,Vba,我有一张Excel 2013表格,上面有很多选项卡。每个选项卡都包含我们公司拥有的不同软件的许可证密钥。然后将许可证绑定到安装该许可证的计算机上。我正在编写一个宏,其中列出了搜索字符串所在的所有选项卡。如果我将inputbox留空,它将列出所有选项卡。但如果我键入要搜索的内容,它只会显示宏消息的结尾 Sub TempMacro() Dim ws As Worksheet SearchListRow = 3 Dim rng As Range Dim FindStin

我有一张Excel 2013表格,上面有很多选项卡。每个选项卡都包含我们公司拥有的不同软件的许可证密钥。然后将许可证绑定到安装该许可证的计算机上。我正在编写一个宏,其中列出了搜索字符串所在的所有选项卡。如果我将inputbox留空,它将列出所有选项卡。但如果我键入要搜索的内容,它只会显示宏消息的结尾

Sub TempMacro()
    Dim ws As Worksheet
    SearchListRow = 3
    Dim rng As Range
    Dim FindSting As String

    FindString = InputBox("Enter a Search value")

    For Each ws In ThisWorkbook.Sheets

        'Set Search Function
        Set rng = Cells.Find(What:=FindString, After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)

        If Not rng Is Nothing Then
            'Record tab name where string was found
            Sheets("LISTS").Range("O" & SearchListRow) = ws.Name
            'incriment row
            SearchListRow = SearchListRow + 1
        Else
            'MsgBox ("Nothing found in " & wb.Name)
        End If
    Next ws
    MsgBox ("End Macro")
End Sub

这是因为您的cells对象不是完全限定的。您所做的只是搜索活动表。您需要在
单元格之前添加
Ws
,以便它在这些工作表中进行搜索

试试这个

Set rng = Ws.Cells.Find(What:=FindString......

另外,
LookAt:=xlWhole
进行精确匹配。对于部分匹配,您必须使用工作完美的
xlPart

!我知道一定是我错过了什么小东西。非常感谢您的快速响应和帮助。