简体   繁体   English

复制最后一行的选择

[英]Copying selection from last row

I have a table, with headers in the range A2:V2 and the data in the range A3:VXX , where XX is the last row number. 我有一张表,标题在A2:V2范围内,数据在A3:VXX范围内,其中XX是最后一行。

I am trying to write a macro which duplicates the values of the last row, but only for columns A:P . 我正在尝试编写一个宏,该宏复制最后一行的值,但仅适用于A:P列。 So Duplicating the values in AXX:PXX . 所以复制AXX:PXX的值。 I have no issues finding and copying the entire last row, however I cannot copy a limited range within it. 我没有发现并复制整个最后一行的问题,但是我不能在其中复制有限的范围。

Apologies earlier for not including the code I have used. 抱歉,不包括我使用的代码。

With Activesheet 
    .cells(.rows.count,1).end(xlup).entirerow.copy 
End With

Instead of the entire row set the range: 而不是整个行设置范围:

Dim lastRow as long

With Activesheet 
    lastRow = .cells(.rows.count,1).end(xlup).Row
    .Range(.Cells(lastrow,"A"),.Cells(lastrow,"P")).copy 
End With

you can use: 您可以使用:

With ActiveSheet
    .Cells(.Rows.Count, 1).End(xlUp).EntireRow.Columns("A:P").Copy
End With

or, since ActiveSheet is the default sheet, simply: 或者,由于ActiveSheet是默认工作表,因此只需:

Cells(Rows.Count, 1).End(xlUp).EntireRow.Columns("A:P").Copy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM