Insert new row below and copy format

brayleyboy

Board Regular
Joined
Nov 24, 2005
Messages
52
Can anyone help me with a small piece of code?

Here is what I need to do.

A user will select a cell or range of cells. I would like a macro which when run would insert a new row below the slected cell(s) and copy the format of the row above the new one into the new row.

Thanks
David
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello,

I Know select is bad, I just cant think of a way round it at the moment.

Try this - untested really!

Code:
Sub copy_from_above()
ActiveCell.Offset(Selection.Rows.Count, 0).Select
Selection.EntireRow.Insert
Rows(ActiveCell.Row).Offset(-1, 0).Copy
Range("A" & ActiveCell.Row).PasteSpecial (xlPasteFormats)
Application.CutCopyMode = False
End Sub

I dont think you really need these lines as it seems to copy the line above anyway

Code:
Rows(ActiveCell.Row).Offset(-1, 0).Copy
Range("A" & ActiveCell.Row).PasteSpecial (xlPasteFormats)


Actually try

Code:
Sub copy_from_above()
ActiveCell.Offset(Selection.Rows.Count, 0).EntireRow.Insert
End Sub

or even

Code:
Sub copy_from_above()
ActiveCell.Offset(Selection.Rows.Count, 0).EntireRow.Insert
Rows(ActiveCell.Row).Offset(Selection.Rows.Count - 1, 0).Copy
Range("A" & ActiveCell.Offset(Selection.Rows.Count, 0).Row).PasteSpecial (xlPasteFormats)
Application.CutCopyMode = False
End Sub

again I don't think you need these

Code:
Rows(ActiveCell.Row).Offset(Selection.Rows.Count - 1, 0).Copy
Range("A" & ActiveCell.Offset(Selection.Rows.Count, 0).Row).PasteSpecial (xlPasteFormats)
Application.CutCopyMode = False
 
Upvote 0
Thanks a lot. This one seemed to work perfectly

Code:
Sub copy_from_above() 
ActiveCell.Offset(Selection.Rows.Count, 0).EntireRow.Insert 
Rows(ActiveCell.Row).Offset(Selection.Rows.Count - 1, 0).Copy 
Range("A" & ActiveCell.Offset(Selection.Rows.Count, 0).Row).PasteSpecial (xlPasteFormats) 
Application.CutCopyMode = False 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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