Search code examples
excelvbaoffice365copy-paste

Copy a range of cells in a row and paste same row/range


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!


Solution

  • 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