复制到一行中的最后一个非空单元格

Copy to last non-empty cell in a row

我想将特定范围内的数据复制到特定 row

中的最后一个活动 cell

现在我使用这个代码:

wrkbook1.Sheets("sheet1").Range("A" & Cells.Rows.Count).End(xlUp).Copy

它只复制最后一个活跃的cell

评论中的行数太多,因为您必须确保 Range 中的 Cells 来自同一个工作表。

'copy from all of sheet1 columns A
with wrkbook1.Sheets("sheet1")
    .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
end with

'paste to next blank row in sheet2 column A
with wrkbook1.Sheets("sheet2")
    .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial
end with