VBA Copy then repeatedly paste

Zakkaroo

Active Member
Joined
Jul 6, 2009
Messages
383
I have a list of Customer Numbers in Column H, going down. The list always Starts in Cell H2 but can end at any point ... H11, H23, H30 etc. I need a macro that:
  1. highlights this range of Cells (however many there may be)
  2. copies this selection
  3. Pastes this selection 53 times starting cell C2
So as an example, lets say our customer list goes from H2 to H11. It will highlight H2 to H11, copy this data, select C2 and Paste, then it will have to move C12 and paste again, then it will have to move to C22 and paste again and so on.

But if our customer list went from cell H2 to H15, it would need to highlight that range, copy it, paste it into C2, then select C16 and paste again. Etc.

I can sort of fathom out a way of doing it, through selecting the data to the end, performing some sort of count at this point, then pasting, moving down by the count value and pasting over and over in a for loop.

But the code eludes my simple mind.

Any help much appreciated
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
Sub Co()
    Range("H2:H" & Range("H2").End(xlDown).Row).Copy Range("C2:C" & Range("H2").End(xlDown).Row).Resize(, 53)
End Sub
 
Upvote 0
Try

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
Range("H2:H" & LR).Copy
For i = 1 To 53
    Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
Next i
Application.CutCopyMode = False
End Sub
 
Upvote 0

Thanks both for the quick replies, as ever this forum comes to my rescue!

I have used Vog's solution and it's worked fantastically! Thanks Vog.

I did give yours a go Sektor, but it seemed to paste it, then move along one Column then paste again, instead of move down x rows and repaste.

Thanks for the response though, appreciate your time.
 
Upvote 0
Code:
Sub Co()
    Range("H2:H" & Range("H2").End(xlDown).Row).Copy Range("C2:C" & Range("H2").End(xlDown).Row).Resize(53 * Range("H2:H" & Range("H2").End(xlDown).Row).Rows.Count)
End Sub
 
Last edited:
Upvote 0
Sektor, your 2nd suggestion provides a run-time error

Instead, try:
Code:
Sub DuplicateMe ()

Dim i As Long, j As Long

i = Range("H" & Rows.Count).End(xlUp).Row - 1
j = i + 1
Range("H2:H" & j).Copy Range("C2:C" & j).Resize(53 * i)

End Sub
 
Upvote 0
Apologies, must have been after I saw it; ignore mine then
 
Upvote 0
Is there any way to target this to specific sheets? I have a very similar need, but my team member names start in A2 on sheet "District" and I need this pasted beginning in A11 on sheet "Input"
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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