2014-01-30 222 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

相關問題