按字母顺序排序

时间:2013-10-24 07:50:00

标签: excel sorting

我有一个具有多个值的列,我想按字母顺序对名称进行排序,如何对其进行排序?示例: - 这就是它现在的样子。

Name                                       |  Code  |  Status

Amanda, Bryan, Zoey, Albert, Macro, Johnny | 33     | Active
Amanda, Bryan, Zoey, Albert, Jeniffer, Mac | 44     | Active  

1 个答案:

答案 0 :(得分:0)

最简单的方法是在VBA中执行此操作。在VBA模块中创建以下两个函数:

Public Function fSort(vValue As String, vDelimiter As String) As String
    'Take a string, split it into an array based on the delimiter,
    'sort it and finally convert it back into a string

    fSort = Join(fSortArray(Split(vValue, vDelimiter)), vDelimiter)

End Function

Function fSortArray(vArray As Variant) As Variant
    'Sort a one dimensional array of string values alphabetically

    Dim vI As Long, vJ As Long
    Dim vTmp As String

    For vI = 0 To UBound(vArray)
        For vJ = vI To UBound(vArray)
            If UCase(vArray(vJ)) < UCase(vArray(vI)) Then
                vTmp = vArray(vI)
                vArray(vI) = vArray(vJ)
                vArray(vJ) = vTmp
            End If
        Next
    Next

    fSortArray = vArray
End Function

然后在单元格公式中使用fSort,如:

=fSort(A3,", ")