vba将范围插入特定列

时间:2017-02-27 17:08:26

标签: excel vba excel-vba

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最终在A列中

1 个答案:

答案 0 :(得分: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