find data on a sheet using a user form

bulkodave

Board Regular
Joined
Apr 27, 2013
Messages
68
Hello
Thank you for looking at my post and i hope someone can help me.
I am using excel 2010

I have created a user form ( first time doing this). It has 2 text boxes and a command button.

Text box 1 is named txtroutnumber.
Text box 2 is named txttrailerarrived
command button is named cmdfind

What i need to is when i type a number in the txtroutnumber box and press the cmdfind button the txttrailerarrived box is filled with the time relevant to that number on the spreadsheet. i.e. txtroutnumber = 20 txttrailerarrived will say 20:30
the spreadsheet is called Inbound Plan, and route range starts in b10. the trailer arrived starts in e10.

i have tried to adapt a macro i have found, but all is does is clear the txtroutnumber box and nothing is displayed in the txttrailerarrived box.

The macro is as follows:
Private Sub cmdfind_Click()
Dim lastrow
Dim routenum As String
lastrow = Sheets("Inbound Plan").Range("B" & Rows.Count).End(xlUp).Row
routnum = txtroutnumber.Text
For currentrow = 10 To lastrow
If Cells(currentrow, 2).Text = routenum Then


txtroutnumber.Text = Cells(currentrow, 2).Text
txttrailerarrived = Cells(currentrow, 4)


End If
Next currentrow
txtroutnumber.SetFocus




End Sub

any help will be greatly appreciated

Many Thanks
Dave
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You said:
and route range starts in b10. the trailer arrived starts in e10.

But then your script says:

txttrailerarrived = Cells(currentrow, 4)


4 is not column "E" 4 is column "D"
 
Upvote 0
Hello thank you for your reply i have change to 5 column E, but it is still clearing all the txtboxes:

Private Sub cmdfind_Click()
Dim lastrow
Dim routenum As String
lastrow = Sheets("Inbound Plan").Range("B" & Rows.Count).End(xlUp).Row
routnum = txtroutnumber.Text
For currentrow = 10 To lastrow
If Cells(currentrow, 2).Text = routenum Then


txtroutnumber.Text = Cells(currentrow, 2).Text
txttrailerarrived = Cells(currentrow, 5)


End If
Next currentrow
txtroutnumber.SetFocus




End Sub
 
Upvote 0
Try this: I found a few problems

Code:
Private Sub cmdfind_Click()
 Dim lastrow
 Dim routenum As String
 lastrow = Sheets("Inbound Plan").Range("B" & Rows.Count).End(xlUp).Row
 routnum = txtroutnumber.Text
 
    For currentrow = 10 To lastrow
        If Cells(currentrow, 2).Text = routnum Then
            txttrailerarrived = Cells(currentrow, 5).Text
         End If
    Next currentrow
 txtroutnumber.SetFocus
End Sub

OK
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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