FindNext in Userform

JacobRH

New Member
Joined
May 25, 2010
Messages
41
Hi all,

I have an Excel Userform that updates existing records. My current form has a "Search" button that uses a value typed into a serach field (txtSearch) and looks through Column D on the DataList (Sheet2) tab for that record. I would like to be able to allow the user to click on the Seach button again to search through the rest of the column for any more matches. Once the row is identified it updates the rest of the control boxes in the userform via a "populate userform" sub. I've been searching around the web and Help documents and found the .FindNext command but I can't seem to get it to work. Below is the current vba I have for the search button. Could someone please help me figure this out?

Thank you,
Jacob

PHP:
Private Sub CommandButton4_Click()
Dim rw As Long             'row the search value was found on'
Dim cell As Range
Dim myVal As String
'validate user input'
If txtSearch.Value = "" Then
    MsgBox "Enter valid Initiative!"
    txtSearch.SetFocus
    Exit Sub
End If
 
'convert the TexBox value to  data type long and get row number'
myVal = txtSearch.Value
On Error Resume Next
    With Sheets("DataList").Range("D:D")
        Set cell = .Find(myVal, LookIn:=xlValues)
        rw = cell.Row
    End With
On Error GoTo 0
 
If rw = 0 Then
    MsgBox "Initiative Not Found"
Else
    Call PopulateTextBoxes(rw)
End If
   
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi Jacob,

The code in this thread could be of help to you.

http://www.mrexcel.com/forum/excel-questions/660400-how-cycle-through-results-vlookup.html

What sequence of operation do you want the user to experience?
Is it: Enter search term>click search button > PopulatingTextBoxes > click search again > PopulateTextBoxes with result of FindNext?

If so you need some flag like the one used in the referenced thread so that the code knows whether the search is an initial search or a subsequent search.
 
Upvote 0
Thanks Jerry. I got pulled away to something else today so I'll take a look at this tomorrow and get back to you if I have any further questions or if I figured it out.
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,908
Members
448,532
Latest member
9Kimo3

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