Sorting rows by pairs

G

Guest

I have a spreadsheet that I need to do some sorting where the information for
each person is on 2 lines. I need to keep the grouped info together. Also,
when I imported this data, it had put to sections together that should have
been seperated. When I do this sort, I would have to eliminate the first 6
spaces. Any help would be greatful. Thanks. Here is an example of what is in
each row:
Row 1:
73.26 0829. DAWSON,ANGELA K D 508347 3 62 4100557000048 070106
073106 167.20 167.20 0.00 0.00 167.20
Row 2:
PROC CO DE - MODIFIER T2002 - U3 070106 073106 167.20 167.20
 
D

Dave Peterson

Maybe you can add two additional columns and sort by those.

The first column would contain the common key for that logical pair of rows.
the second column would just be 1, 2, 1, 2, 1, 2... (just an indicator which row
is which row).

Alternatively, you could put all your data on one row, and sort that.
 
G

Guest

The only problem with all on one row is that there is over 3000 rows of info.
Is there a way to join the two rows when it is imported?
 
D

Dave Peterson

Maybe you could run a macro that takes the even numbered rows and moves them to
the far right--then deletes the even numbered row.

This is kind of specific and you'll have to modify it.

Option Explicit
Sub testme()

Dim iRow As Long

With ActiveSheet
'starts on an even row
For iRow = .Cells(.Rows.Count, "A").End(xlUp).Row To 1 Step -2
.Cells(iRow, "A").Resize(1, 10).Cut _
Destination:=.Cells(iRow - 1, "Z")
.Rows(iRow).Delete
Next iRow
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

It copies columns A:J using this portion:
..Cells(iRow, "A").Resize(1, 10).Cut
(Starting in A, but make the range 1 row by 10 columns.)
Adjust it to match your data.

And then it pastes in the previous row starting in column Z.
Destination:=.Cells(iRow - 1, "Z")
You'll have to change this, too.

Test it against a copy of your worksheet--it'll destroy it if it's wrong!
 
Top