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

时间:2014-01-30 11:46:42

标签: excel-vba vba excel

我似乎无法完成这项工作。我一直被困在

    Rows(rng 5).Select

我要做的是复制活动单元格的行并将复制的单元格插入活动单元格下方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

1 个答案:

答案 0 :(得分:14)

未测试。

这是你在尝试的吗?

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