Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
ASU
 
Posts: n/a
Default find the next empty row

I'm using a userform with textboxes to fill in data. Which then gets placed
in the next available row between C10:C19. So far I have the following code
written. Can anyone help and see what changes I need to make to achieve my
goal?

Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet2")


'find first empty row in database

iRow = ws.Cells(Rows.Count, 1) _
..End(xlUp).Offset(1, 0).Row + 1


'check for a part number
If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
MsgBox "Please enter a date"
Exit Sub
End If
'copy the data to the database
ws.Cells(10, 3).Value = Me.TextBox1.Value
ws.Cells(10, 4).Value = Me.TextBox2.Value
ws.Cells(10, 5).Value = Me.TextBox3.Value
ws.Cells(10, 6).Value = Me.TextBox4.Value
ws.Cells(10, 7).Value = Me.TextBox5.Value

'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox1.SetFocus

End Sub
--
ASU
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default find the next empty row

If you want the first available empty row in a worksheet:

Sub LocatEmptyRow()
'
' identify the first empty row in a worksheet
'
For iRow = 1 To 65536
If Application.CountA(Rows(iRow)) = 0 Then
MsgBox (iRow)
Exit Sub
End If
Next
MsgBox ("Worksheet has no empty rows.")
End Sub

Don't be concerned about the 65536 in the For loop. The loop only continues
until the empty row is found.
--
Gary''s Student


"ASU" wrote:

I'm using a userform with textboxes to fill in data. Which then gets placed
in the next available row between C10:C19. So far I have the following code
written. Can anyone help and see what changes I need to make to achieve my
goal?

Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet2")


'find first empty row in database

iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row + 1


'check for a part number
If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
MsgBox "Please enter a date"
Exit Sub
End If
'copy the data to the database
ws.Cells(10, 3).Value = Me.TextBox1.Value
ws.Cells(10, 4).Value = Me.TextBox2.Value
ws.Cells(10, 5).Value = Me.TextBox3.Value
ws.Cells(10, 6).Value = Me.TextBox4.Value
ws.Cells(10, 7).Value = Me.TextBox5.Value

'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox1.SetFocus

End Sub
--
ASU

  #3   Report Post  
Posted to microsoft.public.excel.misc
ASU
 
Posts: n/a
Default find the next empty row

Thanks for that. But how do I paste the data to the database and clear the
textboxes after it transfirs. I know the last part of my code is wrong, but I
reckon it only needs a small change.
--
ASU


"Gary''s Student" wrote:

If you want the first available empty row in a worksheet:

Sub LocatEmptyRow()
'
' identify the first empty row in a worksheet
'
For iRow = 1 To 65536
If Application.CountA(Rows(iRow)) = 0 Then
MsgBox (iRow)
Exit Sub
End If
Next
MsgBox ("Worksheet has no empty rows.")
End Sub

Don't be concerned about the 65536 in the For loop. The loop only continues
until the empty row is found.
--
Gary''s Student


"ASU" wrote:

I'm using a userform with textboxes to fill in data. Which then gets placed
in the next available row between C10:C19. So far I have the following code
written. Can anyone help and see what changes I need to make to achieve my
goal?

Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet2")


'find first empty row in database

iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row + 1


'check for a part number
If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
MsgBox "Please enter a date"
Exit Sub
End If
'copy the data to the database
ws.Cells(10, 3).Value = Me.TextBox1.Value
ws.Cells(10, 4).Value = Me.TextBox2.Value
ws.Cells(10, 5).Value = Me.TextBox3.Value
ws.Cells(10, 6).Value = Me.TextBox4.Value
ws.Cells(10, 7).Value = Me.TextBox5.Value

'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox1.SetFocus

End Sub
--
ASU

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
Leaving an empty cell empty GRL Excel Discussion (Misc queries) 4 April 22nd 06 05:47 PM
why a reference to an empty cell is not considered empty Nicoscot Excel Discussion (Misc queries) 10 March 10th 06 05:36 AM
Find an empty cell and put a dash in it? markexcel Excel Worksheet Functions 5 October 12th 05 03:47 PM
Using the Find tool in EXCEL TK Excel Worksheet Functions 2 February 11th 05 07:51 PM
Excel has a "Find Next" command but no "Find Previous" command. Michael Fitzpatrick Excel Discussion (Misc queries) 2 January 10th 05 11:45 PM


All times are GMT +1. The time now is 01:06 PM.

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"