2017-02-27 109 views
-1
Dim CopyRng As Range 
LastR = LastRow(Sheets("Sheet3")) 
startrow = 1 
startrow = startrow + 1 
Set CopyRng = Sheets("Sheet3").Range(Sheets("Sheet3").Rows(1), Sheets("Sheet3").Rows(LastR)) 

    'insert copied data in Sheet3 onto inserted rows 
    CopyRng.Copy ActiveSheet.Cells(startrow, 2) 

試圖插入CopyRng到B列,運行代碼CopyRng當列結束了VBA插入範圍爲特定的列

回答

1

你的代碼是不完整的,所以我想你可能會像後如下:

With Sheets("Sheet3") '<--| reference "Sheet3" 
    ... your other code 

    Set CopyRng = Intersect(.UsedRange, .Range(.Rows(1), .Rows(LastR))) '<--| set 'CopyRng' to a "finite" range (not an entire row) 

     'insert copied data in Sheet3 onto inserted rows 
     CopyRng.Copy ActiveSheet.cells(startrow, 2) '<--| paste the "finite" range in Activesheet 

     ... your other code 
End With 
+0

@coffeepls,你通過它嗎? – user3598756