I am creating a worksheet in which the user will use a Userform to insert additional items which are either credits or debits which will be placed on an underlying worksheet. I have two dynamic named ranges, Credits and Debits. Credits starts as A6:D6. Debits starts as A12:C12. When and if the user adds items, I want the new item to go into the first empty row in the relevant range and for a new row to be inserted immediately below the new data. Users may add no items or may add many. They may also go back and insert items on a "second pass" through the document. I have data (totals and other stuff) below the ranges in columns A, B, C and D, so I cannot use
to find the last row as that finds the last row in the whole sheet and inserts the data there.
I use
to add the Credit items and
to add the Debit items.
How do I find the last row in the expanding named ranges and insert a row there so that the data in it becomes part of the relevant range?
Code:
Dim iRow As Long
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
I use
Code:
ws.Cells(iRow, 1).Value = Me.txtCreditDescription.Value
ws.Cells(iRow, 4).Value = Me.txtCreditAmount.Value
Code:
ws.Cells(iRow, 1).Value = Me.txtDebitDescription.Value
ws.Cells(iRow, 3).Value = Me.txtDebitAmount.Value
How do I find the last row in the expanding named ranges and insert a row there so that the data in it becomes part of the relevant range?