|
Option Explicit
Sub test1()
Dim ar, br, i&, j&, n&
ar = [a1].CurrentRegion.Value
ReDim br(1 To UBound(ar) * UBound(ar, 2))
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
n = n + 1
br(n) = ar(i, j)
Next j
Next i
qSort1 br, 1, UBound(br)
[H1].Value = Join(br, ",")
Beep
End Sub
Function qSort1(ByRef ar, ByVal iFirst&, ByVal iLast&, _
Optional ByVal isOrder As Boolean = True)
Dim i&, j&, k&, vTemp1, vTemp2
i = iFirst: j = iLast: vTemp1 = ar((iFirst + iLast) / 2)
While i <= j
If isOrder Then
While ar(i) < vTemp1: i = i + 1: Wend
While vTemp1 < ar(j): j = j - 1: Wend
Else
While ar(i) > vTemp1: i = i + 1: Wend
While vTemp1 > ar(j): j = j - 1: Wend
End If
If i <= j Then
vTemp2 = ar(i): ar(i) = ar(j): ar(j) = vTemp2
i = i + 1: j = j - 1
End If
Wend
If iFirst < j Then qSort1 ar, iFirst, j, isOrder
If i < iLast Then qSort1 ar, i, iLast, isOrder
End Function
|
|