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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| 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 100
For i = n - 1 To 3 Step -1
If Cells(i, 1).Value = 10 Then
For y = 1 To n - i
If Cells(i + y, 1).Value < 10 Then
a = Cells(i, 1).Offset(0, 1).Value
Cells(i, 1).Value = Cells(i + y, 1).Value
Cells(i, 1).Offset(0, 1).Value = Cells(i + y, 1).Offset(0, 1).Value
Cells(i + y, 1).Value = 10
Cells(i + y, 1).Offset(0, 1).Value = a
Exit For
End If
Next
End If
Next
Next
For j = 3 To 100
For i = n - 1 To 3 Step -1
If Cells(i, 1).Value = 20 Then
For z = 1 To n - i
If Cells(i + z, 1).Value < 20 Then
b = Cells(i, 1).Offset(0, 1).Value
Cells(i, 1).Value = Cells(i + z, 1).Value
Cells(i, 1).Offset(0, 1).Value = Cells(i + z, 1).Offset(0, 1).Value
Cells(i + z, 1).Value = 20
Cells(i + z, 1).Offset(0, 1).Value = b
Exit For
End If
Next
End If
Next
Next
For j = 3 To 40
For i = n - 1 To 3 Step -1
If Cells(i, 1).Value = 30 And Cells(i + 1, 1).Value < 30 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 = 30
Cells(i + 1, 1).Offset(0, 1).Value = b
End If
Next
Next
End Sub |