Copy and Paste row by index number in Excel Macro

前端 未结 3 1930
清酒与你
清酒与你 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:31

    I assume that you want to copy Rows(i) and paste it as value in Rows(lastRow). So, you need to replace this line

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

    with these two lines:

    .Rows(i).Copy
    .Rows(lastRow).PasteSpecial xlPasteValues
    

    Or

    .Rows(lastRow).Copy
    .Rows(i).PasteSpecial xlPasteValues
    

    if you want to copy Rows(lastRow) and paste it as value in Rows(i).

    Edit:

    To paste everything (formulas + values + formats), use paste type as xlPasteAll.

    Reference: msdn

提交回复
热议问题