Copy and Paste row by index number in Excel Macro

前端 未结 3 1927
清酒与你
清酒与你 2021-01-14 09:39

I\'m trying to copy an entire row by index number and paste it to another row with a different index number when a certain condition is met (I know the issue is not with the

3条回答
  •  抹茶落季
    2021-01-14 10:19

    Range Copy and Paste

    Syntax

    Range().Copy [Destination]

    The square brackets indicate that Destination is an optional parameter. If you don't designate a Destination range it copies the selection to the clipboard. Otherwise it copies the first range directly to the new location.

    Change this line:

    .Rows(lastRow) = .Rows(i).Value

    To:

    .Rows(lastRow).copy .Rows(i)

    It's worth noting that

    .Rows(lastRow).copy .Cells(i, 1)

    Will also work. Excel will resize the Destination range to fit the new data.

提交回复
热议问题