我設法創建了一個代碼,它使用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