Hi I have a Knowledge database spread sheet that stores defects. It has 4 sheets Instructions, Input, DataSheet and lookuplist. On the Input sheet I have a Search button with VBA code that displays a msgBox and searches for keywords entered then tells you how many it has found. The problem I am having is that I cant work out how to get the code to only search the DataSheet because at present it searches every sheet and I don't want that.
Please can someone help me. here is the code
Sub search()
Dim ws As Worksheet, Found As Range, rngNm As String
Dim myText As String, FirstAddress As String, thisLoc As String
Dim AddressStr As String, foundNum As Integer
myText = InputBox("Enter text to find")
If myText = "" Then Exit Sub
For Each ws In ThisWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(what:=myText, LookIn:=xlValues, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
foundNum = foundNum + 1
rngNm = .Name
AddressStr = AddressStr & .Name & " " & Found.Address & vbCrLf
thisLoc = rngNm & " " & Found.Address
Sheets("DataSheet").Select
Range(Found.Address(RowAbsolute:=False, _
ColumnAbsolute:=False)).Select
MsgBox "Found one """ & myText & """ here!" & vbCr & vbCr & _
thisLoc
Set Found = .UsedRange.FindNext(Found)
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
End With
Next ws
If Len(AddressStr) Then
MsgBox "Found: """ & myText & """ " & foundNum & " times." & vbCr & _
AddressStr, vbOKOnly, myText & " found in these cells"
Else:
MsgBox "Unable to find " & myText & " in this workbook.", vbExclamation
End If
End Sub
Bookmarks