'下面一个模拟结果的表格删除
Option Explicit
Sub test()
Dim i, arr, n, t, j, row, a, b, c, tt, k
ReDim arr(1 To 65536, 1 To 5)
For i = 1 To 20 Step 5
n = 1: row = 5: t = Left(Cells(5, i), 2)
For j = 1 To UBound(arr, 2)
arr(n, j) = Cells(5, (i - 1) + j)
Next
For j = 6 To Cells(65536, i).End(xlUp).row + 1
If t <> Left(Cells(j, i), 2) Then
For a = 1 To n - 1
For b = a + 1 To n
If Val(arr(a, UBound(arr, 2))) > Val(arr(b, UBound(arr, 2))) Then
For c = 1 To UBound(arr, 2)
tt = arr(a, c): arr(a, c) = arr(b, c): arr(b, c) = tt
Next
End If
Next b, a
Cells(row, i).Resize(n, UBound(arr, 2)) = arr
t = Left(Cells(j, i), 2): row = j: n = 1
For k = 1 To UBound(arr, 2)
arr(n, k) = Cells(row, (i - 1) + k)
Next
Else
n = n + 1
For k = 1 To UBound(arr, 2)
arr(n, k) = Cells(j, i - 1 + k)
Next
End If
Next j, i
End Sub |