|
楼主 |
发表于 2015-12-8 16:07
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
似乎无法上传附件……
那就先贴出代码:
- Sub szpx_2()
- Dim arr, ar, br, nr, sr, h&, i&, i2&, j&, j2&, k&, l&, l2&, m&, u&, u2&, tm#, tms#
- tms = Timer
- Debug.Print vbCr; "szpx_2"
-
- tm = Timer
- Sheet1.Activate
- m = [a3].End(4).Row
- arr = [a1].Resize(m, 103)
- h = 2
- ReDim ar(m, 3)
- For i = h + 1 To m
- If arr(i, 102) Then ar(k, 0) = i: ar(k, 1) = arr(i, 103): ar(k, 2) = Val(arr(i, 1)): ar(k, 3) = arr(i, 2): k = k + 1
- Next
- Debug.Print Format(Timer - tm, "0.00s ") & "Get ar"
-
- tm = Timer
- sr = Array(1, 2, 2, 2, 3, 1)
- nr = szpx2(ar, 0, k - 1, sr)
- Debug.Print Format(Timer - tm, "0.00s ") & "Sort"
-
- tm = Timer
- l = LBound(nr): u = UBound(nr)
- l2 = LBound(arr, 2): u2 = UBound(arr, 2)
- ReDim br(l - h To u, l2 To u2)
- For i = 1 To h
- For j2 = l2 To u2
- br(l - h + i - 1, j2) = arr(LBound(arr) + i - 1, j2)
- Next
- Next
- For i = l To u
- i2 = ar(nr(i), 0)
- For j2 = l2 To u2
- br(i, j2) = arr(i2, j2)
- Next
- Next
- Debug.Print Format(Timer - tm, "0.00s ") & "Output"
-
- tm = Timer
- Sheet2.Activate
- [a1].Resize(UBound(br) - LBound(br) + 1, UBound(br, 2) - LBound(br, 2) + 1) = br
- Debug.Print Format(Timer - tm, "0.00s ") & "Output"
-
- Debug.Print Format(Timer - tms, "0.00s ") & "Total"
- MsgBox Format(Timer - tms, "0.00s ") & u - l + 1
- End Sub
- Function szpx2(ar, l&, u&, ParamArray sr()) 'by kagawa 2015/12/4-12/7
- Dim br, y, sr2, i&, i2&, i3&, i4&, j&, j2&, k&, s&, t
-
- ReDim x&(l To u), z(l To u + 1) As Boolean
- For i = l To u
- x(i) = i
- Next
- z(u + 1) = True
-
- If UBound(sr) = 0 Then sr2 = sr(0) Else sr2 = sr
- j = sr2(0): If sr2(1) Mod 2 Then Call QSort1(ar, x, j, l, u) Else Call QSort2(ar, x, j, l, u)
- ' If sr2(1) = 1 Then Call AZE(ar, x, j, l, u)
- For k = 2 To UBound(sr2) Step 2
- j2 = sr2(k): s = sr2(k + 1)
- i = l: t = ar(x(i), j): i2 = i
- Do
- Do
- i2 = i2 + 1: If z(i2) Then Exit Do Else If ar(x(i2), j) <> t Then z(i2) = True: Exit Do
- Loop
- If i2 - 1 > i Then
- If s Mod 2 Then Call QSort1(ar, x, j2, i, i2 - 1) Else Call QSort2(ar, x, j2, i, i2 - 1)
- ' If s = 1 Then Call AZE(ar, x, j2, i, i2 - 1)
- End If
- If i2 > u Then Exit Do Else i = i2: t = ar(x(i), j)
- Loop
- j = j2
- Next
-
- i = l: t = ar(x(i), j2): i2 = i
- Do
- Do
- i2 = i2 + 1: If z(i2) Then Exit Do Else If ar(x(i2), j2) <> t Then Exit Do
- Loop
- If i2 - i > 1 Then Call QSort(x, i, i2 - 1)
- If i2 > u Then Exit Do Else i = i2: t = ar(x(i), j2)
- Loop
-
- szpx2 = x
- ' szpx = szbr(ar, x, h)
- End Function
复制代码
|
|