duplicate a range a specified number of times

G

Guest

How can I copy a range of cells and duplicate it the number of times
specified in a specific cell?

For example cell A1 has 3 as the value. I want to copy A2:B5, and duplicate
it three times (the number in cell A1) and paste side by side in the same
sheet say beginning in cell A7. If cell A1 had a 7 as the value, I want to
copy and duplicate the range 7 times etc.

Thanks!
 
G

Guest

Sub ABC()
Dim rng As Range, dest As Range
Dim i As Long
Set rng = Range("A2:B5")
Set dest = Range("A7")
For i = 1 To Range("A1").Value
rng.Copy dest
Set dest = dest.Offset(0, rng.Columns.Count)
Next
End Sub
 
H

hobbsies

The code would look something like this:

Dim i As Integer, copyRange As Range
Set copyRange = Range("A2:B5")

For i = 1 To Range("A1")
copyRange.Copy
copyRange.Offset(0, i * copyRange.Columns.Count).PasteSpecial
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top