error 400
I have the below code which is sorting a range of data and then inserting a row at each change in column A. The code is working however, at the end of the procedure I am getting an error 400 and I don't know why. The code is below. Thanks for the help.
Public Sub copyrange()
On Error GoTo 0
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Dim i As Long
Dim lastrow As Variant
Application.ScreenUpdating = False
lastrow = Range("a65536").End(xlUp).Row
For i = lastrow To 1 Step -1
If Cells(i, "A") <> Cells(i - 1, "A") Then
Rows(i).Insert
End If
Next i
Application.ScreenUpdating = True
End Sub
|