我设法创建了一个代码,它使用visual basic在Excel数据库内搜索所有选项卡。但是,搜索只会告诉我信息所在的位置,并且不会显示信息。使用VBA在Excel上进行高级搜索和过滤
下面的代码如下:
Sub SearchWordInEntireWorkbook()
Dim ws As Worksheet
Dim strWhat As String
Dim cell As Range
Dim Found As Boolean
strWhat = Application.InputBox("What word do you want to search in this workbook?", "Search Word!", Type:=2)
If strWhat = "" Then
MsgBox "No search word entered.", vbExclamation, "Search Cancelled!"
Exit Sub
End If
For Each ws In Worksheets
With ws.Cells
Set cell = .Find(what:=strWhat, lookat:=xlPart, MatchCase:=False)
If Not cell Is Nothing Then
Found = True
MsgBox "The Word " & strWhat & " is found in " & cell.Address(0, 0) & " on " & ws.Name & " sheet."
End If
End With
Next ws
If Not Found Then
MsgBox "The word " & strWhat & " is not found on any sheet in this workbook.", vbExclamation, "Word Not Found!"
End If
End Sub
我需要的是,当你运行搜索,而不是告诉我在哪里,该数据位于要显示的数据。
请任何人都可以帮我解决这个问题吗?如果您需要任何其他信息,请告诉我。 据我所知,有
“找到=真”,把这段代码 - >“cell.Select – ExcelinEfendisi
就这样做了,这是没有工作:( – Elliot
在此之前,把这个代码以及因为我错过了单元格可能在另一个工作表 - >表格(cell.Parent.Name).Select,或在一行 - > - Application.Goto表单(cell.Parent.Name).range(cell.Address) – ExcelinEfendisi