0

I am trying to work on a procedure to select the second to last row and all rows above it in a worksheet and copy and paste values.

I'm able to find the last row in my spreadsheet and select the entire row but I'm having a hard time offsetting the selected row. I'm getting an error related to the offset parameter.

'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
UnbrokenChain
  • 183
  • 1
  • 5
  • 18

1 Answers1

1

First you are trying to use a number where a range is needed:

'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

Now I assume you are going to try and get the whole range I would change to this:

'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

This will select everything from A1 to column J and down to the second to last line. Change J to the Last column. If you are going to copy and paste it will save time to define the last column.

If you want to copy and past the values back on itself(remove the formulas) then:

'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
Scott Craner
  • 148,073
  • 10
  • 49
  • 81