select倒数第二行以上的所有值并复制并粘贴

我正在尝试在一个过程中select倒数第二行及其上面的所有行,并复制并粘贴值。

我可以在电子表格中find最后一行并select整行,但是我很难抵消所选的行。 我得到一个错误相关的偏移量参数。

'Removes formulas above the last line in the Auto Lease Data Dim ALR As Long Dim ALR2 As Long With Sheets("Auto Lease Data") ALR = .Range("A" & .Rows.Count).End(xlUp).Row ALR2 = .Range("A" & ALR).EntireRow.Select .Range(ALR2).Offset(-1).Activate End With 

首先,您正在尝试使用需要范围的数字:

 'Removes formulas above the last line in the Auto Lease Data Dim ALR As Long Dim ALR2 As Range With Sheets("Auto Lease Data") ALR = .Range("A" & .Rows.Count).End(xlUp).Row Set ALR2 = .Range(ALR -1 & ":" & ALR -1) ALR2.select End With 

现在我假设你将会试着把整个范围都变成这样:

 'Removes formulas above the last line in the Auto Lease Data Dim ALR As Long Dim ALR2 As Range With Sheets("Auto Lease Data") ALR = .Range("A" & .Rows.Count).End(xlUp).Row Set ALR2 = .Range("A1:J" & ALR -1) ALR2.select End With 

这将select从A1到J列的所有内容,然后是从倒数第二行开始。 将J更改为最后一列。 如果您要复制并粘贴,将会节省时间来定义最后一列。

如果你想复制和超过它自己的值(删除公式),然后:

 'Removes formulas above the last line in the Auto Lease Data Dim ALR As Long Dim ALR2 As Range With Sheets("Auto Lease Data") ALR = .Range("A" & .Rows.Count).End(xlUp).Row Set ALR2 = .Range("A1:J" & ALR -1) ALR2.value = ALR2.value End With