Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 347
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 347
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with this conditional IF statement C-Dawg Excel Discussion (Misc queries) 3 May 15th 06 06:01 PM
Instead of a negative number, I'd like to show zero... Dr. Darrell Excel Worksheet Functions 6 December 7th 05 08:21 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
Copy cell format to cell on another worksht and update automatical kevinm Excel Worksheet Functions 21 May 19th 05 11:07 AM
up to 7 functions? ALex Excel Worksheet Functions 10 April 12th 05 06:42 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"