VBA Code to Copy Row, Paste Row Below Last Row

BettyBoop0916

New Member
Joined
May 20, 2011
Messages
16
Hi there,

I'm having difficulty in trying to come up with a VBA code for a macro button that should, once pressed, copy the entire row, paste row below that row, delete all data but keep existing formulas (and outlines if there are any).

This is what I've come up with:

Private Sub CommandButton1_Click()
ActiveCell.EntireRow.Select
Selection.Copy
Selection.Insert
Selection.SpecialCells(xlCellTypeConstants, 3).Select
Selection.ClearContents
Application.CutCopyMode = False

This works in the sense that it inserts the row and deletes the data and keeps the formula, HOWEVER it does not insert it below the last row, but above.

What needs to be done to make this row insert below and not above.

I tried this:

Private Sub CommandButton1_Click()
ActiveCell.EntireRow.Select
Selection.Copy
Selection.Insert shift:=xlDown
Selection.SpecialCells(xlCellTypeConstants, 3).Select
Selection.ClearContents
Application.CutCopyMode = False

But it still did not insert the row below.

Anybody have any suggestions?

This is for my office computer at work...they are running Microsoft Office 2003.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Perhaps

Rich (BB code):
Private Sub CommandButton1_Click()
ActiveCell.EntireRow.Select
Selection.Copy
Selection.Offset(1).Insert
Selection.SpecialCells(xlCellTypeConstants, 3).Select
Selection.ClearContents
Application.CutCopyMode = False
 
Upvote 0
Thanks for the reply...

But, it still didn't work, and I have tried to do that as well, but still end up having the row insert above and not below. It's very strange...in all the forums I've looked at, they all say the same thing.

But I still end up with it not working.

Anything else you can suggest?
 
Upvote 0
This works for me

Code:
Sub btest()
ActiveCell.EntireRow.Select
Selection.Copy
Selection.Offset(1).Insert
Selection.Offset(1).Select
Selection.SpecialCells(xlCellTypeConstants, 3).Select
Selection.ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

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