user form - how to set it up so it stores data when you press
Hi Please ignore the previous post.. I didnt notice the "Enter Key". Try the
below which will update the entries to ColA of Sheet1
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Then
lngRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Sheet1").Range("A" & lngRow) = TextBox1.Text
TextBox1.Text = ""
End If
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"Jacob Skaria" wrote:
Try the Beforeupdate event
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
lngRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(lngRow, 1).Value = TextBox1.Text
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"NDBC" wrote:
Mike,
Thanks for that. It seems like it is exactly what I'm looking for. I tried
copying it in but get this error "Procedure declaration does not match
description of event or procedure having same name". The textbox is called
textbox1 so it is not the name. Is there something else I need.
Thanks
"Mike H" wrote:
You could do it like this which detects the enter key being pressed
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode < 13 Then Exit Sub
mysheet = "Sheet1"
lastrow = Sheets(mysheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
Cells(lastrow, 1).Value = TextBox1.Text
End Sub
Mike
"NDBC" wrote:
Thanks for the replys but neither are quite what I wanted. I can do what both
examples do. That is put in the text box and have a button that does the
command to store the entered data.
What a want is a form with only the text box so that when you hit enter the
data is stored. I don't want to have to either click on the button or press
enter twice.
Can this be done.
|