在excel中查找一对单元对的反转对

时间:2014-02-26 12:11:09

标签: excel excel-vba row directed-graph vba

我有一张表是有向图的图像。

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

如何以对方彼此相邻的方式排列行。 结果应如下所示:

 John, Peter
 Peter, John
 (this gap is for the sake of clarity)
 Dan, John
 John, Dan

1 个答案:

答案 0 :(得分:0)

分三部分进行:

<强> PART#1:

在标准模块中插入以下UDF:

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:

假设您的数据位于 A 列中,请在B1中输入:

= ReOrder(A1)并复制

<强> PART#3:

排序cols A &amp; B B