ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   selecting the next cell down (https://www.excelbanter.com/excel-discussion-misc-queries/110781-selecting-next-cell-down.html)

George

selecting the next cell down
 
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
--
George

Gary''s Student

selecting the next cell down
 
Try:

lastrow.Offset(2, 0).Select

This will move you past the data that you have just entered
--
Gary's Student


"George" wrote:

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
--
George


George

selecting the next cell down
 
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?
--
George


"Gary''s Student" wrote:

Try:

lastrow.Offset(2, 0).Select

This will move you past the data that you have just entered
--
Gary's Student


"George" wrote:

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
--
George



All times are GMT +1. The time now is 04:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com