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
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 = ""

End Sub


You could put this in after the code segment where you add data to the

Application.CutCopyMode = False 'prevent entering clipboard data
ws/Rows(iRow +1).Insert

But I don't know why you would want to do that since you already have found
the last row with data and moved down 10 rows from there to make your last
entry. You are going to end up with a lot of blank rows..

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question