2014-01-30 179 views
1

我似乎无法完成此工作。我一直陷在Excel VBA宏 - 复制并插入复制的单元格

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 
+0

你想在'行(rng 5)中做什么?选择'?这应该通过一个错误导致语法不正确。 –

+0

我正在尝试选择与活动单元格下面5行相同的行。 – NoNo

+1

您是否看到下面的答案? –

回答

10

未经测试。

这是你正在尝试?

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 
+0

这正是我正在寻找的。你真棒Siddharth :)。经测试,它很好 – NoNo

+1

[有趣的阅读](http://stackoverflow.com/questions/10714251/excel-macro-avoiding-using-select) –

+0

Siddharth这绝对是一个很好的文章,并帮助我很多。非常感谢。 – NoNo

相关问题