不好意思,有个BUG,测试5层时发现的,现在已修复:
- Option Explicit
- Const cs = 5 '编码层数
- Public Sub PaiXu()
- Dim arr, n&, i&, j&, j1%, k&, k1%, m%, brr, s1, s2, gd, jg, t#
- t = Timer
- n = Cells(Rows.Count, 1).End(xlUp).Row
- If n > 1 Then arr = Range("a1:a" & n).Value Else ReDim arr(1 To 1, 1 To 1): arr(1, 1) = Range("a1").Value
- jg = arr
- For i = 1 To n
- m = (cs - 1) - (Len(arr(i, 1)) - Len(Replace(arr(i, 1), "-", "")))
- For j = 1 To m
- arr(i, 1) = arr(i, 1) & "-"
- Next j
- Next i
- For i = 1 To cs
- For j = 1 To n - 1 '还是老样子,冒泡排序
- brr = Split(arr(j, 1), "-")
- For j1 = 1 To i '连接对比量
- s1 = s1 & brr(j1 - 1)
- Next j1
- For k = j + 1 To n
- brr = Split(arr(k, 1), "-")
- For k1 = 1 To i '连接对比量
- s2 = s2 & brr(k1 - 1)
- Next k1
- If s1 > s2 Then
- gd = jg(j, 1): jg(j, 1) = jg(k, 1): jg(k, 1) = gd
- gd = arr(j, 1): arr(j, 1) = arr(k, 1): arr(k, 1) = gd
- End If
- s2 = ""
- Next k
- s1 = ""
- Next j
- Next i
- Range("c:c").ClearContents: Range("c1").Resize(n) = jg: Range("d1") = "用时:" & Format(Timer - t, "0.0000") & "秒。"
- End Sub
复制代码 前楼附件会同步更新。
|