PDA

View Full Version : Solved: Can I insert a copied row with a macro?



deocder
05-10-2009, 08:00 PM
Hello,

Looking for some help getting my macro to insert a copied row as outlined below. It's probably pretty simple but I am not familiar with the code.

On the attached sheet, I am trying to copy row 24 (which contains formulas and other conditional formatting) and, upon clicking the "Insert Row" button I have linked to the macro, will insert that row below the last filled in row, in this case after row 32. I say insert and not just copy formatting because there is data in row 33 that is needed by the charts. In this case, after inserting the new row, the data in row 33 will be in 34.

Bob Phillips
05-11-2009, 01:03 AM
Is this what you want



Sub ADD_ROW()

A = Int(InputBox("How many rows?", "DATA ENTRY"))
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Rows(LastRow).Resize(A, 1).Insert Shift:=xlDown
Rows(24).Copy Range("A" & LastRow).Resize(A, 1)
End Sub

deocder
05-11-2009, 07:45 AM
Thanks xld,

This does insert the correct row, but does not shift, in this case, row 33 down. In other words, the macro overwrites the values in row 33 instead of inserting the copied cell.

Bob Phillips
05-11-2009, 08:03 AM
It shunts them down for me.

deocder
05-11-2009, 08:26 AM
It does this for the value in column A, but I also have values in column X,Y,Z, AC,AD,and AE that do not shift down. Does it shift the values in those columns down for you?

I am using Excel 2003.

Bob Phillips
05-11-2009, 08:42 AM
That was just plain dumb!"



Sub ADD_ROW()

A = Int(InputBox("How many rows?", "DATA ENTRY"))
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Rows(LastRow).Resize(A).Insert Shift:=xlDown
Rows(24).Copy Range("A" & LastRow).Resize(A)
End Sub

deocder
05-11-2009, 01:38 PM
YES! This is exactly what I want it to do!

Thank you xld!

deocder
05-12-2009, 05:40 AM
If I hide row 24, referenced in the code above, the inserted row is also hidden. If I want to keep row 24 hidden, is there a way to unhide the inserted row?

Bob Phillips
05-12-2009, 07:58 AM
Sub ADD_ROW()

A = Int(InputBox("How many rows?", "DATA ENTRY"))
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Rows(LastRow).Resize(A).Insert Shift:=xlDown
Rows(24).Copy Range("A" & LastRow).Resize(A)
Rows(LastRow).Resize(A).Hidden = False
End Sub

deocder
05-15-2009, 11:54 AM
Exactly, thank you for your help!