VBA code: copy/paste/insert until end of list

dwarnimont

Board Regular
Joined
Jan 12, 2010
Messages
71
I have a list of parts. I'd need to copy/paste/insert the same 4 rows under each part #, until end of list. Simply, it would be like this (assume my source to be copied from is rows 1-4.
starting in 1st part #, paste insert rows under existing row. go down 5 rows which will now be under the next new part number and do again, until list is complete.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try:

Code:
Sub Test()
    Dim r As Long
    For r = 4 To 1 Step -1
        Range("A" & r).Copy
        Range("A" & r + 1).Resize(4).Insert Shift:=xlDown
    Next r
End Sub
 
Upvote 0
thanks, yet i may not have been clear. The source to be copied is always rows 1-4 as a group. copy & insert under every row that is below row 4. do until end of list.
 
Upvote 0
Code:
Sub Insert_Four_Copied_Rows()

    Dim Lastrow As Long, Lastcol As Long, r As Long
    
    Lastrow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Lastcol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
    Application.ScreenUpdating = False
    
    For r = Lastrow To 5 Step -1
    
        Range("A1").Resize(4, Lastcol).Copy
        Range("A" & r + 1).Insert Shift:=xlDown
        
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Like this?

Code:
Sub Test()
    Dim LastRow As Long
    Dim r As Long
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    For r = LastRow To 5 Step -1
        Range("A1:A4").Copy
        Range("A" & r + 1).Insert Shift:=xlDown
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

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