VBA insert 5 rows above the last row

armagan56

New Member
Joined
Feb 10, 2009
Messages
31
1 1
2 3
3 2
4
5 6



Hi I have a spreadsheet with a total on the last row, I want a macro to insert 5 blank rows above the total row (listed at row 5 in the above example) at the bottom.

the trouble is of course as soon as you insert 5 rows, then next time I need to run this, the macro will need to detect which is the total row again before inserting another 5 rows.

any help/advice would be appreciated.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Sub Insert_Rows()

Application.ScreenUpdating = False

Dim Last_Row As Long

With Sheets("Sheet1")

    Last_Row = Range("A" & Rows.Count).End(xlUp).Row
    
    Range(.Cells(Last_Row, 1), .Cells(Last_Row + 4, 1)).EntireRow.Insert

End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Possibly... (if I understand)

Code:
Sub Foo()
RATR = Range("A" & Rows.Count).End(xlUp).Row - 1   ' Get the Row number just above the current Total Row
Range("A" & RATR).Select
ActiveCell.Resize(5).EntireRow.Insert shift:=xlDown
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

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