Home > database >  Copy a range of cells in a row and paste same row/range
Copy a range of cells in a row and paste same row/range

Time:10-24

Thats my data. I want to copy B2:M9 and insert it to P2. Furher, I want to copy B13:M20 and paste it to P2. Then I want to copy B24:M31 and paste it to P2 and so on. Does anyone have an idea how I can do it?

My data

Thank you!

CodePudding user response:

Sub copypasta()

Dim nb_iter as Integer 'Number of ranges you have to copy
nb_iter = 3 'for example
Dim step as Integer
step = 0 

for k = 1 to nb_iter
Range("B" & step   2, "M" & step   9).Copy
Range("P2").PasteSpecial , Paste:=xlPasteValues
step = step   11 'you are adding 11 to both row numbers for each iteration
Next k

End Sub

CodePudding user response:

My first attempt:

Sub Copypasta()
  Dim i As Long
    For i = 0 To 31
    Range("B" & 2   i, "M" & 9   i).Copy
    Range("P2").PasteSpecial Paste:=xlPasteValues
    Next i

End Sub
  • Related