VBA to copy and paste range N times

jbench18

New Member
Joined
Feb 12, 2013
Messages
24
Hey, looking for some help with a code that will copy a range of data and paste x numbers of times depending on what value is selected. In addition I would need column A (starting in A8) reference how many times the data set was copied. Thanks in Advance

Drop Down Box: B1

Range of Data: Starting at B8:K8 (Could be 1 row or 1k + plus) so would need offset function

Example:

B1 = 3

Range of Data: B8:K22, copy range and paste starting in row 23. Repeat 1 more time (3 total) bc of value in B1

For Column A:
A8: A22 = 1
A23: A37 = 2
A38 : 52 = 3
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this

Code:
Sub copy_paste_range()
    Dim r As Range, i As Long, n As Long
    Set r = Range("B8:K22")
    If Not IsNumeric(Range("B1").Value) Then Exit Sub
    For i = 1 To Range("B1").Value
        n = n + r.Rows.Count
        r.Copy r.Offset(n)
    Next
End Sub
 
Upvote 0
How about
Code:
Sub jbench18()
   Dim Usdrws As Long, i As Long
   Usdrws = Range("B" & Rows.Count).End(xlUp).Row
   
   Range("B8:K" & Usdrws).Copy Range("B" & Usdrws + 1).Resize((Usdrws - 7) * (Range("B1") - 1), 10)
   For i = 1 To Range("B1").Value
      Range("A8").Offset((i - 1) * (Usdrws - 7)).Resize(Usdrws - 7).Value = i
   Next i
End Sub
 
Upvote 0
Hey guys, sorry for the late response. @Fluff the code worked perfectly. Thank you very much for your help!

How about
Code:
Sub jbench18()
   Dim Usdrws As Long, i As Long
   Usdrws = Range("B" & Rows.Count).End(xlUp).Row
   
   Range("B8:K" & Usdrws).Copy Range("B" & Usdrws + 1).Resize((Usdrws - 7) * (Range("B1") - 1), 10)
   For i = 1 To Range("B1").Value
      Range("A8").Offset((i - 1) * (Usdrws - 7)).Resize(Usdrws - 7).Value = i
   Next i
End Sub
 
Upvote 0
You're welcome & thanks for the feedback

As a matter of interest did Dante's code work as well?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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