|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim arr, i, j, k, a, b
With Sheets("需排序表")
arr = .Range("a2:f" & .Cells(Rows.Count, "f").End(xlUp).Row + 1)
arr(UBound(arr, 1), 1) = "?": arr(UBound(arr, 1), 2) = "辅导员"
For i = 2 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If arr(j + 1, 2) = "辅导员" Then
For k = j To i Step -1
If Len(arr(k, 2)) Then Exit For
Next
For a = i To k
For b = a To k
If Len(arr(b + 1, 1)) > 0 Or Len(arr(b + 1, 2)) = 0 Then
If b > a Then Call dsort(arr, a, b, 2, UBound(arr, 2), 6)
a = b: Exit For
End If
Next b, a
i = j + 1: Exit For
End If
Next j, i
End With
Sheets("排序完成表").[a2].Resize(UBound(arr, 1) - 1, UBound(arr, 2)) = arr
End Sub
Function dsort(arr, first, last, left, right, key)
Dim i, j, k, t, a, b
For i = first To last - 1
For j = i + 1 To last
a = arr(i, key): b = arr(j, key)
If Not IsNumeric(a) Then
For k = 1 To Len(a)
If IsNumeric(Mid(a, k, 1)) Then
a = Mid(a, k): b = Mid(b, k): Exit For
End If
Next
End If
If Val(a) > Val(b) Then
For k = left To right
t = arr(i, k): arr(i, k) = arr(j, k): arr(j, k) = t
Next
End If
Next j, i
End Function |
|