Find last cell in named ranges and insert a new row

inarbeth

Well-known Member
Joined
Apr 8, 2002
Messages
912
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
Code:
Dim iRow As Long
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
to find the last row as that finds the last row in the whole sheet and inserts the data there.
I use
Code:
 ws.Cells(iRow, 1).Value = Me.txtCreditDescription.Value
ws.Cells(iRow, 4).Value = Me.txtCreditAmount.Value
to add the Credit items and
Code:
 ws.Cells(iRow, 1).Value = Me.txtDebitDescription.Value
ws.Cells(iRow, 3).Value = Me.txtDebitAmount.Value
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?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Bump. Can anyone assist with this please? Another way of describing what I am doing is to use the Userform to add data to the row above the last row in the range and then to insert a new row below that row.
 
Upvote 0

Forum statistics

Threads
1,203,600
Messages
6,056,205
Members
444,850
Latest member
dancasta7

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top