|
Option Explicit
Sub TEST6()
Dim ar, br, cr, i&, j&, r&, dic As Object, vKey
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = [B1].CurrentRegion.Value
For i = 2 To UBound(ar)
br = Split(ar(i, 1), "、")
dic(br(0)) = dic(br(0)) & "|" & br(1)
Next i
r = 1
For Each vKey In dic.keys
br = Split(dic(vKey), "|")
ReDim cr(1 To 2, 1 To UBound(br))
For i = 1 To UBound(br)
cr(1, i) = br(i)
cr(2, i) = Val(Split(br(i), "+")(1)) '(1)
Next i
bSort cr, 1, UBound(cr), 1, UBound(cr, 2), 2
For i = 1 To UBound(cr, 2)
r = r + 1
ar(r, 1) = vKey & "+" & cr(1, i)
Next i
Next
[C1].Resize(UBound(ar)) = ar
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
Function bSort(ByRef ar, ByVal iFirst&, ByVal iLast&, ByVal iLeft&, _
ByVal iRight&, ByVal iKey&, Optional isOrder As Boolean = True)
Dim i&, j&, k&, vTemp
For i = iLeft To iRight - 1
For j = iLeft To iRight + iLeft - 1 - i
If ar(iKey, j) <> ar(iKey, j + 1) Then
If ar(iKey, j) < ar(iKey, j + 1) Xor isOrder Then
For k = iFirst To iLast
vTemp = ar(k, j)
ar(k, j) = ar(k, j + 1)
ar(k, j + 1) = vTemp
Next
End If
End If
Next j
Next i
End Function
|
|