UserForm Next Record Same Last Name

LikeButtah1

New Member
Joined
Apr 17, 2018
Messages
34
Hello All,
I am trying to find the next record of the same last name that the user will type into textbox1. I can have another button to navigate through the records but after finding the last record it should say "Last Record Found". Column A holds the last names and first record starts in A3. Here is the code that finds the first instance of the last name in textbox1:

Code:
Dim blnNew As Boolean
Dim TRows, i As Long




Private Sub btnLName_Click()


                blnNew = False
                txtLastName.Text = ""
                txtFirstName.Text = ""
                txtC.Text = ""
                txtNewCard.Text = ""
                txtAccDes.Text = ""
                txtAccCreated.Text = ""
                txtAccGranted.Text = ""
                txtAccCancelled.Text = ""
                txtAccCategory.Text = ""
                txtNotes.Text = ""
   
    TRows = Worksheets("PNG Database").Range("A1").CurrentRegion.Rows.Count
    For i = 3 To TRows
        If LCase(Worksheets("PNG Database").Cells(i, 1).Value) = LCase(TextBox1.Text) Then
                
            txtLastName.Text = Worksheets("PNG Database").Cells(i, 1).Value
            txtFirstName.Text = Worksheets("PNG Database").Cells(i, 2).Value
            txtC.Text = Worksheets("PNG Database").Cells(i, 3).Value
            txtNewCard.Text = Worksheets("PNG Database").Cells(i, 4).Value
            txtAccDes.Text = Worksheets("PNG Database").Cells(i, 5).Value
            txtAccCreated.Text = Worksheets("PNG Database").Cells(i, 6).Value
            txtAccGranted.Text = Worksheets("PNG Database").Cells(i, 7).Value
            txtAccCancelled.Text = Worksheets("PNG Database").Cells(i, 8).Value
            txtAccCategory.Text = Worksheets("PNG Database").Cells(i, 9).Value
            txtNotes.Text = Worksheets("PNG Database").Cells(i, 12).Value
         
            Exit For
        End If
    Next i
    
   


End Sub

Any help would be great. Thanks in advance.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
When did it do that?
When you tried to download it, or when you tried to open it?
 
Upvote 0
Not sure why it's doing that. :confused:
I've just logged in anonymously & it didn't ask for a password.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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