Macro to copy and paste a range of values numerous times

peppa_chami

New Member
Joined
Jan 13, 2016
Messages
7
Hi All,

I would like to have some help regarding the following macro. I would like to copy a range of values in a certain column and paste it down the same column 365 times, with offsetting one row. For an example;

1) Copy A2:A682 (This will always be the same)
2) Paste it in A684:A1364
3) Then in A1366:A2046

Like wise this needs to be pasted 365 times, always offsetting 1 row.

Could you please help me with a macro for this. Greatly appreciate any help.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This should do it test on a COPY of your worksheet

Code:
Sub CopyDown()

    Dim x As Integer
    Dim i As Integer
    i = 682
    
    
    ActiveSheet.Cells(2, 1).Resize(681, 1).Select
    
    For x = 1 To 365
        i = i + 2
        Selection.Copy Destination:=Cells(i, 1)
        i = i + 680
        
    Next x
    
    


End Sub
 
Last edited:
Upvote 0
Alternate suggestion to try:
Code:
Sub CopyMacro()

    Dim arr()   As Variant
    Dim x       As Long
    
    arr = range("A2:A683").value
    
    Application.ScreenUpdating = False

    For x = 1 To 365
        Cells(rows.count, 1).End(xlUp).Offset(2).Resize(UBound(arr, 1)).value = arr
    Next x
    
    Application.ScreenUpdating = True
    
    Erase arr

End Sub
 
Last edited:
Upvote 0
JackDanIce,

I am trying very hard to learn arrays as it is definitely faster in almost all cases, I suspect in this instance there will not be a lot in it
as you are also looping 365 times
 
Upvote 0
@Dryver in this situation not a lot, but I too am learning arrays so trying to code with them as much as I can.

I would argue there is some gain (vs yours) from not doing an incremental calculation (i = i + 2) and repeated copy + paste, using the clipboard to repeatedly copy and hold the data.

Agreed though, both suggestions 'write' to the worksheet the same number of times which likely to be the main bottle neck. Alternative is to loop and use the input array to create an output array (ReDim), then 'write' out in single pass.
 
Upvote 0
I only copy once outside the loop though
To me it looks like you copy inside the loop:
Rich (BB code):
Sub CopyDown()

    Dim x As Integer
    Dim i As Integer
    i = 682
    
    ActiveSheet.Cells(2, 1).Resize(681, 1).Select
    
    For x = 1 To 365
        i = i + 2
        Selection.Copy Destination:=Cells(i, 1)
        i = i + 680
        
    Next x
    
End Sub
Also, Integers are pretty much a redundant data type in Excel:
https://msdn.microsoft.com/en-us/library/office/aa164506(v=office.10).aspx
 
Upvote 0
That's interesting, surely this will devastate my 8gig of ram now its not a bit reference any more lol
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

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