Hello, I'm very new to VB macro coding and am seeking guidance on how to create a macro that will;
1. search for a name in a spreedsheet when the command button is clicked then
2. display the associated row values in userform textboxes then
3. if another command button (or the same command button) is clicked again then
4. display the next matched name in the userform textboxes then
5. repeat from step 3 until the find has completed searching though the names column.
I tried to do it myself, but it is proving to be a bit too advanced for a novice like myself.
Attached is the code I have so far;
As you most likely can see, all the above code will do is show me the value of specified cell in the row of only the first match to my find request.
I have had no luck with tring to enable the findnext command, your help with surely save me hours of searching and experimating.
Thanks muchly, Ozhally
1. search for a name in a spreedsheet when the command button is clicked then
2. display the associated row values in userform textboxes then
3. if another command button (or the same command button) is clicked again then
4. display the next matched name in the userform textboxes then
5. repeat from step 3 until the find has completed searching though the names column.
I tried to do it myself, but it is proving to be a bit too advanced for a novice like myself.
Attached is the code I have so far;
Code:
Private Sub cmdfamily_Click()
Dim SearchRange As Range
Dim FindRow As Range
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheet1
Set ws2 = Sheet2
Set SearchRange = ws2.Range("B:B")
Set FindRow = SearchRange.find("smith", LookIn:=xlValues, LookAt:=xlWhole, searchformat:=False)
Me.lblfirst.Text = ""
Me.lblref.Text = ""
Me.lbldue.Text = ""
Me.lbladdress.Text = ""
Me.lblUR.Text = ""
Me.lblloans.Text = ""
Me.lbltelephone.Text = ""
If FindRow Is Nothing Then
msgbox "No match found for " & Me.lbllast
Me.lbllast.Text = ""
End If
If Not FindRow Is Nothing Then
Me.lblfirst.Text = ws2.Cells(FindRow.Row, 3).Value
Me.lblref.Text = ws2.Cells(FindRow.Row, 1).Value
Me.lbldue.Text = ws2.Cells(FindRow.Row, 7).Value
Me.lbladdress.Text = ws2.Cells(FindRow.Row, 5).Value
Me.lblUR.Text = ws2.Cells(FindRow.Row, 4).Value
Me.lblloans.Text = ws2.Cells(FindRow.Row, 9).Value
Me.lbltelephone.Text = ws2.Cells(FindRow.Row, 6).Value
End If
End Sub
I have had no luck with tring to enable the findnext command, your help with surely save me hours of searching and experimating.
Thanks muchly, Ozhally