Sub ordina()
Application.ScreenUpdating = False
LR1 = Sheets(1).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Sheets(1).Range("A1:B" & LR1).Copy Sheets(2).Range("A1")
Sheets(2).Sort.SortFields.Clear
Sheets(2).Select
With ActiveSheet.Sort
.SortFields.Add Key:=Range("A2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
.SetRange Range("A2:B" & LR1)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
r1 = 2
r = r1
Do While Cells(r, 1) <> ""
ord = 0
Do While Cells(r, 1) = Cells(r + 1, 1)
If Cells(r, 2) = "ORD" Then ord = 1
r = r + 1
Loop
If Cells(r, 2) = "ORD" Then ord = 1
If ord = 1 Then
Range("A" & r1 & ":A" & r).EntireRow.Delete
r1 = r1: r = r1
Else
If r > r1 Then
Range("A" & r1 & ":A" & r - 1).EntireRow.Delete
End If
r1 = r1 + 1: r = r1
End If
Loop
Columns(2).Delete
Application.ScreenUpdating = True
End Sub
|