|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 一把小刀闯天下 于 2018-6-20 10:00 编辑
'被吊打之人设计的表格,写起来确实费劲
Option Explicit
Sub test()
Dim i, j, k, arr, cnt, first, stp, a, b, c, t
arr = Range("a2:h" & Cells(Rows.Count, "c").End(xlUp).Row + 1)
arr(UBound(arr, 1), 1) = "flag"
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If IsNumeric(arr(j, 7)) And Len(arr(j, 7)) > 0 Then first = j: cnt = 0: Exit For
Next
For j = first To UBound(arr, 1) - 1
If IsNumeric(arr(j, 7)) And Len(arr(j, 7)) > 0 Then cnt = cnt + 1
If Len(arr(j + 1, 1)) > 0 And Len(arr(j + 1, 7)) = 0 Then
stp = (j - first + 1) / cnt
For a = first To j - stp Step stp
For b = a + stp To j Step stp
If arr(a, 7) < arr(b, 7) Then
For c = 1 To stp
For k = 1 To UBound(arr, 2)
t = arr(a + c - 1, k): arr(a + c - 1, k) = arr(b + c - 1, k): arr(b + c - 1, k) = t
Next k, c
End If
Next b, a
i = j: Exit For
End If
Next j, i
[a2].Resize(UBound(arr, 1) - 1, UBound(arr, 2)) = arr
End Sub
|
评分
-
1
查看全部评分
-
|