Option Explicit
Sub TEST2()
Dim ar, br, cr, dr, i&, j&, k&, strJoin$
Application.ScreenUpdating = False
br = Array("10 20 30", "01 11 21 31", "02 12 22 32", "03 13 23 33", _
"04 14 24", "05 15 25", "06 16 26", "07 17 27", "08 18 28", "09 19 29")
ar = Range("C1", Intersect(ActiveSheet.UsedRange, Columns("C:K"))).Value
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
If Len(ar(i, j)) Then
strJoin = ""
For k = 1 To Len(ar(i, j))
strJoin = strJoin & " " & br(Mid(ar(i, j), k, 1))
Next k
cr = Split(strJoin)
ReDim dr(1 To UBound(cr), 1 To 2)
For k = 1 To UBound(cr)
dr(k, 1) = cr(k): dr(k, 2) = Val(cr(k))
Next k
bSort dr, 1, UBound(dr), 1, 2, 2
ar(i, j) = Join(Application.Transpose(Application.Index(dr, , 1)))
End If
Next j
Next i
Columns("P:XFD").Clear
With [P1].Resize(UBound(ar), UBound(ar, 2))
.Value = ar
.EntireColumn.AutoFit
End With
Application.ScreenUpdating = True
Beep
End Sub
Function bSort(ar, iFirst&, iLast&, iLeft&, iRight&, _
iKey&, Optional isOrder As Boolean = True)
Dim i&, j&, k&, vTemp
For i = iFirst To iLast - 1
For j = iFirst To iLast + iFirst - 1 - i
If ar(j, iKey) <> ar(j + 1, iKey) Then
If ar(j, iKey) < ar(j + 1, iKey) Xor isOrder Then
For k = iLeft To iRight
vTemp = ar(j, k)
ar(j, k) = ar(j + 1, k)
ar(j + 1, k) = vTemp
Next
End If
End If
Next j
Next i
End Function
|