Excel VBA宏 - 复制并插入复制的单元格

NoN*_*oNo 2 excel vba excel-vba

我似乎无法完成这项工作.我一直坚持下去

    Rows(rng 5).Select
Run Code Online (Sandbox Code Playgroud)

我要做的是复制活动单元格的行并将复制的单元格插入活动单元格下方5行的行中.

Sub CopyConcatenate()


    Dim ws As Worksheet
    Dim rng As Range

    Set rng = ActiveCell.Rows

    rng.Select
    Selection.Copy
    Rows(rng 5).Select
    Selection.Insert Shift:=xlDown

End Sub
Run Code Online (Sandbox Code Playgroud)

Sid*_*out 15

未经测试.

这是你在尝试什么?

Sub CopyConcatenate()
    Dim ws As Worksheet
    Dim rng As Range

    '~~> Set this to the relevant worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")

    With ws
        '~~> Set your range
        Set rng = .Rows(ActiveCell.Row)

        '~~> Copy the range
        rng.Copy

        '~~> Insert the range
        rng.Offset(5).Insert Shift:=xlDown

        '~~> Clear the clipboard. More importantly remove the
        '~~> ant like borders
        Application.CutCopyMode = False
    End With
End Sub
Run Code Online (Sandbox Code Playgroud)