将列从工作表复制到另一个

时间:2016-08-04 20:57:00

标签: excel vba copy

我的代码出了点问题我无法弄明白。

我想将column Cworkbook 1的{​​{1}}复制到worksheet wsCopyFrom_OFP column D workbook 2worksheet wsCopyTo具有值的行将被复制

LastRow_OFP = wsCopyFrom_OFP.Cells(wsCopyFrom_OFP.Rows.Count, "C").End(xlUp).Row

For i = 4 To LastRow_OFP
    wsCopyFrom_OFP.Cells(i, 3).Copy
    erow = wsCopyTo.Cells(wsCopyTo.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    wsCopyFrom_OFP.Paste Destination:=Worksheets(wsCopyTo).Cells(erow, 1)
Next i

非常感谢

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码

LastRow_OFP = wsCopyFrom_OFP.Cells(wsCopyFrom_OFP.Rows.Count, "C").End(xlUp).Row
For i = 4 To LastRow_OFP
    wsCopyFrom_OFP.Cells(i, 3).Copy wsCopyTo.Range("A" & wsCopyTo.Range("A" & Rows.Count).End(xlUp).Row + 1)
Next i

编辑#1

尝试使用以下代码

    LastRow_OFP = wsCopyFrom_OFP.Cells(wsCopyFrom_OFP.Rows.Count, "C").End(xlUp).Row
    For i = 4 To LastRow_OFP
        wsCopyFrom_OFP.Range("C" & i & ":C" & i + 3).Copy
        wsCopyTo.Range("A" & wsCopyTo.Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial (xlPasteValues)
    Next i