'没看懂先猜一个,按层级升序,,,
Option Explicit
Sub test()
Dim arr, i, j, t
arr = Range("a3:b" & Cells(Rows.Count, "b").End(xlUp).Row).Resize(, 9).Value
For i = 3 To UBound(arr, 1)
t = Split(Replace(arr(i, 2), Space(1), vbNullString), "-")
arr(i, 9) = Format(UBound(t), String(5, "0"))
For j = 0 To UBound(t)
arr(i, 9) = arr(i, 9) & "-" & Format(t(j), String(5, "0"))
Next
For j = j To 4
arr(i, 9) = arr(i, 9) & "-" & String(5, "0")
Next
Next
Call qsort(arr, 3, UBound(arr, 1), 2, 9, 9)
[j3].Resize(UBound(arr, 1), UBound(arr, 2) - 1) = arr
End Sub
Function qsort(arr, first, last, left, right, key)
Dim i As Long, j As Long, k As Long, x As String, t As String
i = first: j = last: x = arr((first + last) / 2, key)
While i <= j
While StrComp(arr(i, key), x, vbTextCompare) = -1: i = i + 1: Wend
While StrComp(x, arr(j, key), vbTextCompare) = -1: j = j - 1: Wend
If i <= j Then
For k = left To right
t = arr(i, k): arr(i, k) = arr(j, k): arr(j, k) = t
Next
i = i + 1: j = j - 1
End If
Wend
If first < j Then qsort arr, first, j, left, right, key
If i < last Then qsort arr, i, last, left, right, key
End Function |