BadHorsie
11-29-2006, 05:03 PM
Hi all
I've written a little and supposedly simple code to insert rows between entries that are different.. i.e. what i have is something like this:
John 21 34
John 25 20
John 344 35
Peter 22 1
Peter 35 1
and I want it to look like this:
John 21 34
John 25 20
John 344 35
Peter 22 1
Peter 35 1
Here is my code:
Sub InsertRows()
Dim rownum As Integer
rownum = 1
Do
rownum = rownum + 1
If StrComp(Cells(rownum, 1), Cells(rownum - 1, 1), 1) <> 0 Then
Rows("rownum:rownum").Select
Selection.Insert Shift:=xlDown
End If
Loop While rownum < 100
End Sub
and it returns an error (at the Selection.Insert Shift:=xlDown line)
can anyone help me with this problem?
Thanks, Pat
I've written a little and supposedly simple code to insert rows between entries that are different.. i.e. what i have is something like this:
John 21 34
John 25 20
John 344 35
Peter 22 1
Peter 35 1
and I want it to look like this:
John 21 34
John 25 20
John 344 35
Peter 22 1
Peter 35 1
Here is my code:
Sub InsertRows()
Dim rownum As Integer
rownum = 1
Do
rownum = rownum + 1
If StrComp(Cells(rownum, 1), Cells(rownum - 1, 1), 1) <> 0 Then
Rows("rownum:rownum").Select
Selection.Insert Shift:=xlDown
End If
Loop While rownum < 100
End Sub
and it returns an error (at the Selection.Insert Shift:=xlDown line)
can anyone help me with this problem?
Thanks, Pat