ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing Marco (https://www.excelbanter.com/excel-programming/413842-changing-marco.html)

JBoyer

Changing Marco
 
I currently have two marcos that I would like to slightly change. They were
originally what I wanted, until I realized that by inserting and deleting
rows they were messing up other data on my sheet. Here are the two I have:

Sub InsertFiveRows()
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
v = Rows(LastRow - 1).Formula
Cells(LastRow - 1, "A").Resize(5, 1).EntireRow.Insert
Rows(LastRow - 1) = v
Rows(LastRow + 4).ClearContents
Range("AU2:BG6").Copy Cells(LastRow, "A")
End Sub

Sub DeleteFiveRows()
Dim lr As Long, x As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
x = lr - 5
ActiveSheet.Rows(x & ":" & lr -1).Delete
End Sub

Can you help me so that I can shift the cells up or down rather than
inserting and deleting cells.


All times are GMT +1. The time now is 08:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com