Hi all
I have butchered the below code to run a simple search for a name in a single column and present a message box to confirm the result and highlight. The code although not pretty, works perfectly, so I would like to use the same code on another sheet.
The other sheet is roughly the same, however the names are listed across, not down. I ahve tried to adjust the code to look across, but it wont accept the use of range letter?
Can anybody let me know how I can make this work please, or a better solution if you have one.
Thanks As Always
I have butchered the below code to run a simple search for a name in a single column and present a message box to confirm the result and highlight. The code although not pretty, works perfectly, so I would like to use the same code on another sheet.
The other sheet is roughly the same, however the names are listed across, not down. I ahve tried to adjust the code to look across, but it wont accept the use of range letter?
Can anybody let me know how I can make this work please, or a better solution if you have one.
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
Dim Correct As String
Dim StartRow As String
Unlocker
Range("C:BC").Interior.ColorIndex = 0
Range("F10").Select
StartRow = 1
Prompt = ""
With Sheets("RECORD")
Do While True
RetValue = InputBox(Prompt & "Who are you looking for?")
If RetValue = "" Then
Exit Do
End If
TryAgain:
Set Rng = .Columns("E:E").Find(What:=RetValue, After:=.Range("E" & StartRow), _
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
Output = MsgBox("Are you looking for """ & Found & "", vbYesNoCancel)
If Output = 6 Then
'Output = 6(Yes)
Range("C" & RowCrnt & ":" & "BC" & RowCrnt).Interior.ColorIndex = 22
ElseIf Output = 7 Then
'Output = 7(No)
StartRow = RowCrnt
GoTo TryAgain
Else
'Output = 2(Cancel)
Locker
Exit Sub
End If
End If
Prompt = Prompt & vbLf
Loop
End With
Locker
End Sub
Thanks As Always