2013-10-24 358 views
0

我有一個具有多個值的列,我想按字母順序排序名稱,我該如何排序?例如: - 這是它現在的樣子。按字母順序排序

Name          | Code | Status 

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

我把你們的名字是單個細胞內的多。你會考慮帶有'''分隔符的文本到列,按字母順序對列進行排序,然後用連接重新組合? – pnuts

回答

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,", ")