View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JeffK JeffK is offline
external usenet poster
 
Posts: 53
Default How to insert row after data from user form

I have the following code for a user form and would like to have it also add
a row after the information has been posted in the database (that way other
information that's located below the database keeps getting pushed down when
items are added and will always provide a spot for the next entry)

Private Sub cmdAdd_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Loan Summary and Comments")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(10, 0).Row

'check for Loan type
If Trim(Me.txtloantype.Value) = "" Then
Me.txtloantype.SetFocus
MsgBox "Please enter Loan Type"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 2).Value = Me.txtloantype.Value
ws.Cells(iRow, 3).Value = Me.txtAmount.Value
ws.Cells(iRow, 4).Value = Me.txtTerm.Value
ws.Cells(iRow, 5).Value = Me.txtAmortization.Value
ws.Cells(iRow, 6).Value = Me.txtRate.Value

'clear the data
Me.txtloantype.Value = ""
Me.txtAmount.Value = ""
Me.txtTerm.Value = ""
Me.txtAmortization.Value = ""
Me.txtRate.Value = ""
Me.txtloantype.SetFocus

End Sub