0

I have a table that is an image of directed graph.

 John, Peter
 John, Dan
 Peter, John
 Dan, John

How to arrange rows in a such way that pairs would appear next to each other. The result should look like:

 John, Peter
 Peter, John
 (this gap is for the sake of clarity)
 Dan, John
 John, Dan
Community
  • 1
  • 1
Aidis
  • 1,272
  • 4
  • 14
  • 31

1 Answers1

0

Do this in three parts:

PART#1:

Insert the following UDF in a standard module:

Public Function ReOrder(sIn As String) As String
    s = Replace(sIn, " ", "")
    ary = Split(s, ",")
    If ary(0) < ary(1) Then
        ReOrder = ary(0) & "," & ary(1)
    Else
        ReOrder = ary(1) & "," & ary(0)
    End If
End Function

PART#2:

Assuming you data is in column A, in B1 enter:

=ReOrder(A1) and copy down

PART#3:

Sort cols A & B by B

Gary's Student
  • 95,722
  • 10
  • 59
  • 99