FindNext or SearchNext VBA Help

bettygoodspeed

New Member
Joined
Aug 31, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone,
I created a basic data entry form. I didnt use the insert userform, instead I just used a small macro to allow the user to enter data into the 'form' and then have it populate the spreadsheet on another tab. (so they dont mess up the main data).

I want to allow the users to be able to search by name but we do have some duplicate records (intentionally). Ideally, they could click the search button and enter Smith, then if its not the right Smith, they can click next or something like that. I have been trying for days to get this darn thing to work. My code for the search is below... I'm so grateful for any assistance. I've googled and googled but no luck. Please help. Thank you so much.

'search box
searchvalue = sourcesheet.Range("C8").Value

'Is Name in there already?
If searchvalue <> vbNullString Then

'search code
Set Rng = dataidcol.find(what:=searchvalue, _
LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)


If Not Rng Is Nothing Then
'if yes
nextrow = Rng.Row
Else
'input new record
nextrow = datasheet.Range("G" & datasheet.Rows.Count).End(xlUp).Offset(1).Row

End If
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Not sure I fully understand what your code is doing, but the code below would allow a user to see what is in the found cell and the cell to the right of the found cell then decide if it is correct. If not it will then look for the search item in a different location. If no other target is found or if the target is found then the code would continue to the next step.
VBA Code:
Dim adr As String, ques As Variant, desc As String
'search box
 searchvalue = sourcesheet.Range("C8").Value
 'Is Name in there already?
    If searchvalue <> vbNullString Then
        'search code
        Set rng = dataidcol.Find(what:=searchvalue, _
        LookIn:=xlValues, lookat:=xlWhole, _
        searchorder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
        If Not rng Is Nothing Then
        'if yes
            adr = rng.Address
            Do
                desc = rng.Value & " " & rng.Offset(, 1).Value
                ques = MsgBox(desc & vbLf & "Is This The Correct Target?", vbQuestion + vbYesNo, "EVALUATE")
                If ques = vbYes Then Exit Do
                Set rng = dataidcol.FindNext(rng)
            Loop While rng.Address <> adr
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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