VBA to copy certain column from active row, insert new row and paste

MAP

Active Member
Joined
Mar 22, 2007
Messages
312
Office Version
  1. 2007
Platform
  1. Windows
I am a newbie to VBA using Excel 2010. I want Excel to (1) copy cells B:H of the active row, (2) insert one row below the active row, and (3) paste the values of the recently copied cells into the new blank row.

So far, the only knowledge I have gathered allows me to simply copy the entire active row and paste that below using...

ActiveCell.EntireRow.Select
Selection.Copy
Selection.Insert shift:=x1down

I will appreciate being taught how to only copy certain cells of active row to paste below. Thank you.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
VBA Code:
Sub test()
With ActiveCell
Range("B" & .Row & ":H" & .Row).Copy
Range("B" & .Row & ":H" & .Row).Insert shift:=xlDown
End With
Application.CutCopyMode = False
End Sub
 
Upvote 0
Another option
VBA Code:
Sub MAP()
With ActiveCell
   .Offset(1).EntireRow.Insert
   Range("B" & .Row).Resize(2, 7).FillDown
End With
End Sub
 
Upvote 0
Solution
Bebo021999, I thank you for your help. I tried your code and it worked. However it did not work for me as intended. I wanted to simply have Excel insert one row below the active cell and then copy the contents in column B:H of the active cell into the newly inserted row. With your code, Excel did not insert an entire row, but it only inserted cells in column B:H below the active cell and then it copied the active cell row contents. This code left the contents in column A unmoved.

I also tried the code provided by Fluff. This did work as intended.

I appreciate everyone's help and tutoring.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,414
Messages
6,119,373
Members
448,888
Latest member
Arle8907

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