使用Excel VBA在工作簿中查找匹配项,并仅返回所需的结果

时间:2016-03-23 21:44:37

标签: excel vba excel-vba

我有一个电子表格用于一年中的每个月,我的宏搜索每个月的特定值,显示弹出窗口是否已找到。

我想要做的只是显示与我的查询匹配的结果(我显示每次迭代(月)的结果,即使它没有找到)。

Sub Search()
res = InputBox("Who are you looking for?")
For w = 2 To Worksheets.Count
With Worksheets(w)
Set Rng = .Cells   '<<  The Entire Sheet is Searched
With Rng
    Set MyChoice = .Find(What:=res)
    If Not MyChoice Is Nothing Then
    Application.Goto MyChoice
    MsgBox "Found " & res & " in " & Worksheets(w).Name
    Else
    MsgBox "Not Found! " & res & " in " & Worksheets(w).Name
    End If
End With
End With
Next w
Worksheets(1).Activate


End Sub

非常感谢!

0 个答案:

没有答案