[英]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.