Last Value into Textbox

perku

New Member
Joined
Aug 18, 2016
Messages
9
Please help!!

I have a userform for data entry and i want the textbox3 on this userform to display the last entry (an 8 digit code) in column E when the commandbutton is pressed to enter the data.
i am using the below code and cannot get it to work.

TextBox3.Value = Worksheets("Sheet1").Range("E1").End(xlDown).Value

Using excel 2013

Ryan
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Does this work?
Code:
TextBox3.Value = Worksheets("Sheet1").Range("E" & Rows.Count).End(xlUp).Value
 
Upvote 0
How/where/when are you running the code?
 
Upvote 0
Private Sub CommandButton1_Click()
If Len(TextBox1.Value) < 33 Then
MsgBox "Invalid Product Barcode"
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
Else
If Len(TextBox2.Value) < 5 Then
MsgBox "Invalid Location Barcode"
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
Else
If Len(TextBox2.Value) > 5 Then
MsgBox "Invalid Location Barcode"
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
Else
Dim LastRow As Object


Set LastRow = Sheet1.Range("a65536").End(xlUp)


LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox2.Text

TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Value = Worksheets("Sheet1").Range("E" & Rows.Count).End(xlUp).Value
TextBox4.Value = Worksheets("Sheet1").Range("g1").End(xlDown).Value
TextBox5.Value = Worksheets("Sheet1").Range("h1").End(xlDown).Value
TextBox6.Value = Worksheets("Sheet1").Range("f1").End(xlDown).Value
TextBox7.Value = Worksheets("Sheet1").Range("j1").End(xlDown).Value
TextBox8.Value = Worksheets("Sheet1").Range("i1").End(xlDown).Value
TextBox1.SetFocus


End If
End If
End If
End Sub
 
Upvote 0
Yes

Columns E to J are parts of the the values in column A and B which the userform is inserting. ie column E = "=LEFT(A2,8)".
 
Upvote 0
If all the text box's values are supposed to come from the same row, you could use this
Code:
With Sheets("Sheet1").Range("E:E")
    With .Find("?*", after:=.Cells(1, 1), LookIn:=xlValue, lookat:=xlWhole, searchdirection:=xlPrevious)
        TextBox3.Text = .Value
        TextBox4.Text = .Offset(0, 2).Value
        TextBox5.Text = .Offset(0, 3).Value
        TextBox6.Text = .Offset(0, 1).Value
        TextBox7.Text = .Offset(0, 5).Value
        TextBox8.Text = .Offset(0, 4).Value
    End With
End With

If not, each text box would need its own .Find line
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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