selecting the next cell down

G

Guest

Below I have the following code. A userform with textboxes. When I press
commandbutton 1 it transfirs all the data to the worksheet.
How can I insert a command so that the active cell selected is the next
empty row down in column "A".

Private Sub CommandButton1_Click()
Dim lastrow As Object

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

lastrow.Offset(1, 0).Value = TextBox2.Text
lastrow.Offset(1, 1).Value = TextBox1.Text
lastrow.Offset(1, 2).Value = TextBox8.Text
lastrow.Offset(1, 3).Value = TextBox3.Text
lastrow.Offset(1, 4).Value = TextBox4.Text
lastrow.Offset(1, 7).Value = TextBox7.Text



MsgBox "One record written to Data Sheet"

response = MsgBox("Do you want to enter another record?", vbYesNo)

If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""

TextBox1.SetFocus

Else
Unload Me
End If

End Sub
 
G

Guest

Try:

lastrow.Offset(2, 0).Select

This will move you past the data that you have just entered
 
G

Guest

Thanks Gary that was quick.
How would I place it in the code included on my question. Or would it go in
as a seperate code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top