新学的集合排序,就用了(弱于数组排序),供参考。
Sub test()
Dim ar(), c As New Collection, tmp1, tmp2
ar = Range("A2:a17").Value
tmp1 = Val(Mid(ar(1, 1), 2))
c.Add ar(1, 1), "b" & tmp1
For i% = 2 To UBound(ar)
tmp1 = Val(Mid(ar(i, 1), 2))
For Each tmp2 In c
tmp2 = Val(Mid(tmp2, 2))
If tmp2 >= tmp1 Then Exit For
Next
If tmp2 = Empty Then
c.Add ar(i, 1), "b" & tmp1
Else
If tmp2 <> tmp1 Then
c.Add ar(i, 1), "b" & tmp1, before:="b" & tmp2
Else '用于解决关键字相同。排序结果不是“稳定的”
i2 = i2% + 1
c.Add ar(i, 1), "b" & i2 & tmp1, before:="b" & tmp2
End If
End If
Next
i = 0
For Each tmp2 In c
i = i + 1
ar(i, 1) = tmp2
Next
Range("c2").Resize(i) = ar
End Sub
|