Findnext and previousnext code

lo123123

New Member
Joined
Nov 9, 2017
Messages
4
Hey fellas,
I have a userform with everything working fine aprt from my Find_Next and previous command. What happens is that it keeps giving the same results while it should finding all data that matches by search criteria. If anyone could help me in this, I would really appreciate.
Private Sub CB_FIND_NEXT_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_Taken
For currentrow = 2 To lastrow
If Cells(currentrow, 11).Text = Action_Taken Then
txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text
End If
Next currentrow
txtAction_Taken.SetFocus
End Sub
Private Sub CB_FIND_PREVIOUS_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_Taken
For currentrow = lastrow To 2 Step -1
If Cells(currentrow, 11).Text = Action_Taken Then
txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text
End If
Next currentrow
txtAction_Taken.SetFocus
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
If you put your code between code tags and indent it, someone might want to look at it.
 
Upvote 0
Private Sub CB_FIND_NEXT_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_Taken

For currentrow = 2 To lastrow
If Cells(currentrow, 11).Text = Action_Taken Then

txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text

End If
Next currentrow
txtAction_Taken.SetFocus
End Sub

Private Sub CB_FIND_PREVIOUS_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_Taken

For currentrow = lastrow To 2 Step -1
If Cells(currentrow, 11).Text = Action_Taken Then

txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text

End If
Next currentrow
txtAction_Taken.SetFocus
End Sub
 
Upvote 0
At the beginning of the code, you put [ code] (leave the space out.)
At the end of the code, you put ( /code] (again, leave the space out
Your post should look like
Code:
    'Here is all your code. Maybe lots of lines
 
Upvote 0
Code:
Private Sub CB_FIND_NEXT_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_TakenFor currentrow = 2 To lastrow
If Cells(currentrow, 11).Text = Action_Taken Then
txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text
End If
Next currentrow
txtAction_Taken.SetFocus
End Sub
Private Sub CB_FIND_PREVIOUS_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_Taken
For currentrow = lastrow To 2 Step -1
If Cells(currentrow, 11).Text = Action_Taken Then
txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text
End If
Next currentrow
txtAction_Taken.SetFocus
End Sub
 
Upvote 0
Just a clarification, the code bellow is supposed to help me find next items on my userform. Instead, it brings results of the last row on a search criteria. I donr know if it is the problem with wrong range or row definition. I ma sorry I had problems posting the code in a right format earlier. I hop some one would help.
Thanks

Code:
Private Sub CB_FIND_NEXT_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_TakenFor currentrow = 2 To lastrow
If Cells(currentrow, 11).Text = Action_Taken Then
txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text
End If
Next currentrow
txtAction_Taken.SetFocus
End Sub

Private Sub CB_FIND_PREVIOUS_Click()
Dim lastrow
Dim Action_Taken As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Action_Taken = txtAction_Taken
For currentrow = lastrow To 2 Step -1
If Cells(currentrow, 11).Text = Action_Taken Then
txtDate_Rcvd.Text = Cells(currentrow, 1).Text
txtFormat_Rcvd.Text = Cells(currentrow, 2).Text
txtIn_Out.Text = Cells(currentrow, 3).Text
txtPhone_No.Text = Cells(currentrow, 4).Text
txtCaller.Text = Cells(currentrow, 5).Text
txtViolator.Text = Cells(currentrow, 6).Text
txtBP_No.Text = Cells(currentrow, 7).Text
txtTaxType.Text = Cells(currentrow, 8).Text
txtResponseSent.Text = Cells(currentrow, 9).Text
txtTypeofResponse.Text = Cells(currentrow, 10).Text
txtAction_Taken.Text = Cells(currentrow, 11).Text
txtLead_Number.Text = Cells(currentrow, 12).Text
txtNonPursefolder_DOCName.Text = Cells(currentrow, 13).Text
txtComments.Text = Cells(currentrow, 14).Text
End If
Next currentrow
txtAction_Taken.SetFocus
End Sub
 
Upvote 0
Code:
Dim where As Range, whatt As String
    whatt = "Nice Stuff"
    Set c = Range("D:D")
    Set where = c.Find(what:=whatt, after:=c(1), searchdirection:=xlPrevious)    '<----xlPrevious or xlNext
    MsgBox where.Address(0, 0)

Can you change and fit the part you need into your code?

If not, explain in a couple sentences what you want to do.
I am sorry but I don't wade through 50 lines of code that have nothing to do with the problem.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
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