|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
'这不是排序,只是有条件对换。可以试一下
Option Explicit
Sub test()
Dim i, j, arr, pos, p
pos = Range("j39:k" & Cells(Rows.Count, "j").End(xlUp).Row)
arr = [a1].CurrentRegion
ReDim t(1 To UBound(arr, 1))
For i = 1 To UBound(pos, 1): pos(i, 2) = i + 3: Next
For i = 1 To UBound(pos, 1)
For j = 3 To UBound(arr, 2)
If arr(2, j) = pos(i, 1) Then p = j: Exit For
Next
If j < UBound(arr, 2) + 1 Then
For j = 2 To UBound(arr, 1)
t(j) = arr(j, pos(i, 2))
arr(j, pos(i, 2)) = arr(j, p)
arr(j, p) = t(j)
Next
End If
Next
[a1].CurrentRegion = arr
End Sub |
|