Excel VBA .find命令不为我工作

我有一个Excel 2013工作表,有很多选项卡。 每个选项卡都拥有我们公司拥有的不同软件的许可证密钥。 该许可证然后绑定到它所安装的计算机上。 我正在编写一个macros,列出了searchstring所在的所有选项卡。 如果我把input框留空,它会列出所有的标签。 但是,如果我input一些东西来search它没有任何东西,但显示macros消息的结束。

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 

这是因为您的单元格对象不完全合格。 你在做什么只是searchactivesheet。 您需要在Cells之前添加Ws ,以便在这些表单中进行search

尝试这个

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

LookAt:=xlWhole确实匹配。 对于部分匹配,您将不得不使用xlPart