|
再给你一个已知可以乱序的,有序输出的。
- Sub Test3()
- Dim St As String, i&
- For i = 2 To 10
- St = Cells(i, 1).Value
- Cells(i, 2) = "'" & JoinSt(St)
- Next
- End Sub
- Function JoinSt(St$)
- Dim Dic As Object, i&, Ar, Nr(), N&, Dk, S$, Mn, Mx, T
- Set Dic = CreateObject("Scripting.Dictionary")
- S = Replace(St, ",", ",")
- Ar = Split(S, ",")
- N = UBound(Ar)
- ReDim Nr(N)
- For i = 0 To N
- Nr(i) = ExtNum(Ar(i))
- Dic(Nr(i)) = i
- Next 'i
- Dk = Dic.Keys
- Mn = Application.WorksheetFunction.Min(Dk)
- S = Ar(Dic(Mn)): Dic.Remove Mn
- Do
- T = "": Mx = Mn + 1: While Dic.Exists(Mx): T = Ar(Dic(Mx)): Dic.Remove Mx: Mx = Mx + 1: Wend
- If T <> "" Then S = S & ":" & T
- If Dic.Count > 0 Then
- Dk = Dic.Keys
- Mn = Application.WorksheetFunction.Min(Dk)
- S = S & "," & Ar(Dic(Mn)): Dic.Remove Mn
- End If
- Loop Until Dic.Count = 0
- JoinSt = S
- Set Dic = Nothing
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|