示例,我拥有的一个单元格具有值:
1133,1131,1141,1142,1143,1151,1132,1181
如何按升序进行此操作?
1131,1132,1133,1141,1142,1143,1151,1181
这样做可以处理很多不同的事情,所以希望找到一个公式或vba函数驱动的解决方案。
答案 0 :(得分:2)
Option Explicit
Function sortingHat(str As String, _
Optional delim As String = ",")
Dim a As Long, b As Long, arr As Variant, tmp As Variant
'split the string into an array
arr = Split(str, delim)
'sort the array
For a = LBound(arr) To UBound(arr) - 1
For b = a + 1 To UBound(arr)
If arr(b) < arr(a) Then
tmp = arr(a)
arr(a) = arr(b)
arr(b) = tmp
End If
Next b
Next a
'join the array into a string
sortingHat = Join(arr, delim)
End Function
答案 1 :(得分:0)