0

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

Name                                       |  Code  |  Status

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

1 回答 1

0

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

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,", ")
于 2013-10-24T08:17:11.667 回答