1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Sub x()
Dim a, b As Integer
n = Range("A" & Rows.Count).End(xlUp).Row
Range("A3:B" & n).Sort Key1:=Range("B3"), Order1:=xlDescending, Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
For j = 1 To 20
For i = n - 1 To 3 Step -1
If Cells(i, 1).Value = 10 And Cells(i + 1, 1).Value < 10 Then
a = Cells(i, 1).Offset(0, 1).Value
Cells(i, 1).Value = Cells(i + 1, 1).Value
Cells(i, 1).Offset(0, 1).Value = Cells(i + 1, 1).Offset(0, 1).Value
Cells(i + 1, 1).Value = 10
Cells(i + 1, 1).Offset(0, 1).Value = a
End If
Next
Next
For j = 3 To n - 1
For i = n - 1 To 3 Step -1
If Cells(i, 1).Value = 20 And Cells(i + 1, 1).Value < 20 Then
b = Cells(i, 1).Offset(0, 1).Value
Cells(i, 1).Value = Cells(i + 1, 1).Value
Cells(i, 1).Offset(0, 1).Value = Cells(i + 1, 1).Offset(0, 1).Value
Cells(i + 1, 1).Value = 20
Cells(i + 1, 1).Offset(0, 1).Value = b
End If
Next
Next
End Sub |
Partager