Search box to look across not down

LORDMARKS

New Member
Joined
Jun 5, 2014
Messages
39
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.


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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top