Sub sort_differently()
Dim L_ro, T, TA As Integer
Application.ScreenUpdating = False
L_ro = Sheets("Before").Cells(1, 1).End(xlDown).Row
Sheets("After").Range("K1").EntireColumn.Insert
Sheets("Before").Range("A1:A" & L_ro).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("After").Range( _
"K1"), Unique:=True
L_ro = Sheets("After").Cells(1, "K").End(xlDown).Row
With Sheets("After")
For T = 1 To L_ro
For TA = 0 To 9
If Val(Right(.Cells(T, "K"), 1)) = TA Then
If .Cells(1, TA + 1) = "" Then
.Cells(1, TA + 1) = .Cells(T, "K")
ElseIf .Cells(2, TA + 1) = "" Then
.Cells(2, TA + 1) = .Cells(T, "K")
Else
.Range(Cells(1, TA + 1).Address).End(xlDown).Offset(1, 0).Value = .Cells(T, "K")
End If
Exit For
End If
Next TA
Next T
End With
Sheets("After").Range("K1").EntireColumn.Delete
Application.ScreenUpdating = True
End Sub
Bookmarks