Hello,
The following code finds the first completely empty row, but I want it to insert the data on the same row as the first empty cell in column D. If anyone could help me with this I'd be elated.
Thanks,
Brian
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("People")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtName1.Value) = "" Then
Me.txtName1.SetFocus
MsgBox "Please enter new person."
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 4).Value = Me.txtName1.Value
ws.Cells(iRow, 5).Value = Me.txtName2.Value
ws.Cells(iRow, 7).Value = Me.txtLOR.Value
ws.Cells(iRow, 2).Value = Me.txtRl.Value
ws.Cells(iRow, 10).Value = Me.txtGender.Value
ws.Cells(iRow, 8).Value = Me.txtbrthyear.Value
'clear the data
Me.txtName1.Value = ""
Me.txtName2.Value = ""
Me.txtLOR.Value = ""
Me.txtRl.Value = ""
Me.txtGender.Value = ""
Me.txtbrthyear.Value = ""
Unload Me
The following code finds the first completely empty row, but I want it to insert the data on the same row as the first empty cell in column D. If anyone could help me with this I'd be elated.
Thanks,
Brian
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("People")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtName1.Value) = "" Then
Me.txtName1.SetFocus
MsgBox "Please enter new person."
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 4).Value = Me.txtName1.Value
ws.Cells(iRow, 5).Value = Me.txtName2.Value
ws.Cells(iRow, 7).Value = Me.txtLOR.Value
ws.Cells(iRow, 2).Value = Me.txtRl.Value
ws.Cells(iRow, 10).Value = Me.txtGender.Value
ws.Cells(iRow, 8).Value = Me.txtbrthyear.Value
'clear the data
Me.txtName1.Value = ""
Me.txtName2.Value = ""
Me.txtLOR.Value = ""
Me.txtRl.Value = ""
Me.txtGender.Value = ""
Me.txtbrthyear.Value = ""
Unload Me