Option Explicit
Sub test()
Dim i, j, pos, arr, t
arr = [a1].CurrentRegion
For i = UBound(arr, 1) To 2 Step -1
If arr(i, 1) = "甲" Then
For j = i - 1 To 2 Step -1
If arr(j, 1) <> "甲" Then pos = j: Exit For
Next
For j = pos To 2 Step -1
If arr(j, 1) = "甲" Then
t = arr(pos, 1): arr(pos, 1) = arr(j, 1): arr(j, 1) = t
t = arr(pos, 2): arr(pos, 2) = arr(j, 2): arr(j, 2) = t
i = pos: Exit For
End If
Next
Else
For j = i To 2 Step -1
If arr(j, 1) = "甲" Then
t = arr(i, 1): arr(i, 1) = arr(j, 1): arr(j, 1) = t
t = arr(i, 2): arr(i, 2) = arr(j, 2): arr(j, 2) = t
Exit For
End If
Next
End If
Next
For i = 2 To UBound(arr, 1)
If arr(i, 1) = "甲" Then pos = i: Exit For
Next
For i = 2 To pos - 2
For j = i + 1 To pos - 1
If arr(i, 2) < arr(j, 2) Then
t = arr(i, 1): arr(i, 1) = arr(j, 1): arr(j, 1) = t
t = arr(i, 2): arr(i, 2) = arr(j, 2): arr(j, 2) = t
End If
Next j, i
For i = pos To UBound(arr, 1) - 1
For j = i + 1 To UBound(arr, 1)
If arr(i, 2) < arr(j, 2) Then
t = arr(i, 1): arr(i, 1) = arr(j, 1): arr(j, 1) = t
t = arr(i, 2): arr(i, 2) = arr(j, 2): arr(j, 2) = t
End If
Next j, i
[m1].Resize(UBound(arr, 1), UBound(arr, 2)) = arr '作比较用,自己修改
End Sub |