Hi All
I found some code online to run a basic value search on a column. I have modified it to suit my needs, but as I would like to add the function to "Try Again" if the returned result is not the correct one.
I need this because the search is for names, and the sheet used by lots of people, so they might search for type "James" and get the wrong result, so a button or function to say try again, that would look for the next occurance would be great.
Thanks if anyone can help with this
I found some code online to run a basic value search on a column. I have modified it to suit my needs, but as I would like to add the function to "Try Again" if the returned result is not the correct one.
I need this because the search is for names, and the sheet used by lots of people, so they might search for type "James" and get the wrong result, so a button or function to say try again, that would look for the next occurance would be great.
Thanks if anyone can help with this
Code:
Sub SearchName()
Application.ScreenUpdating = False
Dim Prompt As String
Dim RetValue As String
Dim Found As String
Dim Rng As Range
Dim RowCrnt As Long
Unlocker
Range("C:BC").Interior.ColorIndex = 0
Range("F10").Select
Prompt = ""
With Sheets("RECORD")
Do While True
RetValue = InputBox(Prompt & "Who are you looking for?")
If RetValue = "" Then
Exit Do
End If
Set Rng = .Columns("E:E").Find(What:=RetValue, After:=.Range("E1"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Rng Is Nothing Then
Prompt = "I could not find """ & RetValue & """"
Else
RowCrnt = Rng.Row
Found = Range("E" & RowCrnt).Value
Application.ScreenUpdating = True
Range("F" & RowCrnt).Select
Range("C" & RowCrnt & ":" & "BC" & RowCrnt).Interior.ColorIndex = 22
Prompt = "I have highlighted """ & Found & """ on row " & RowCrnt
End If
Prompt = Prompt & vbLf
Loop
End With
Locker
End Sub
Last edited: