0

I want to copy and paste dynamic range. Especially paste with duplicate value for each source of copy range. Here is code I created from recording a macro:

Sub copyRange()
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("L2:S7").Select
ActiveSheet.Paste

Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Range("L8:S13").Select
ActiveSheet.Paste

Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Range("L14:S19").Select
ActiveSheet.Paste

Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=3
Range("L20:S25").Select
ActiveSheet.Paste
End Sub

this is screenshot output i want:

enter image description here

1
  • Thanks Prasar Khode for correction my queston Feb 12, 2016 at 7:25

1 Answer 1

1
Sub CopyPasteData()
Dim lRw As Long, lRw_2 As Long, x As Long, rActive As Range

Set rActive = ActiveCell
lRw = Cells(Rows.Count, "A").End(xlUp).Row

Application.ScreenUpdating = False

Range("K2:R" & Rows.Count).ClearContents

For i = 2 To lRw
    x = x + 1
    Range("A" & i & ":H" & i).Copy
    lRw_2 = Cells(Rows.Count, "K").End(xlUp).Row + 1
    With Range("K" & lRw_2).Resize(6)
        .PasteSpecial xlPasteAll
        .Offset(, -1).Value = x
    End With
Next i

Application.CutCopyMode = False
rActive.Select
Application.ScreenUpdating = True

End Sub
2
  • Many thanks Sixthense it's working but when I run sub CopyPasteData once again or two time it's repeat copy data to range target after all source copy range. I want just one time only, not repeating when run that sub. Many Thank's for you help. Feb 8, 2016 at 6:27
  • Added Range("K2:R" & Rows.Count).ClearContents line in the above code to clear the old entries.
    – Sixthsense
    Feb 8, 2016 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.