Subject: error 400
Posted By: davidspeare Post Date: 9/29/2005 12:51:41 PM
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

Reply By: danbush Reply Date: 10/1/2005 2:40:58 PM
David

1.  What is the exact description for error 400?
2.  It helps to set up the whole picture for us first:  What are you inserting rows into (Excel, datagrid, etc.)?
3.  The last for next-loop is checking against Cells(i - 1) which on i=1 would be 0.  Does the Cells collection have a valid Row(0)?  If not, that is your problem.


Go to topic 35267

Return to index page 462
Return to index page 461
Return to index page 460
Return to index page 459
Return to index page 458
Return to index page 457
Return to index page 456
Return to index page 455
Return to index page 454
Return to index page 453