Code:
Sub jb()
Dim cell As Range
With Range("A2", Cells(Rows.Count, "B").End(xlUp))
For Each cell In .Columns(2).Cells
With cell
If .Value2 < .Offset(, -1).Value2 Then
.Cut
.Offset(, -1).Insert
End If
End With
Next cell
.Sort Key1:=.Cells(1), Header:=xlNo
End With
End Sub
Hello SHG and thanks for take time to answer my puzzle
What you did is a lot better but it does not finish the job. Let me explain please.
Here is an example of data I work with:
<tbody>
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q069R01
[/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q072R08
[/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q074R01
[/TD]
[TD="bgcolor: #A9D08E"]
Q010R12
[/TD]
[TD="bgcolor: #A9D08E"]
Q036R15
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q020R44
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q022R42
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R71
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q022R26
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q010R02
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q072R08
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q074R01
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q069R01
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q010R02
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q074R01
[/TD]
</tbody>
Your macro brings this back :
<tbody>
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q069R01
[/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q072R08
[/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q074R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q010R02
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #FFFF00"]
Q010R02
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #A9D08E"]
Q010R12
[/TD]
[TD="bgcolor: #A9D08E"]
Q036R15
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q020R44
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q022R42
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R71
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q022R26
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q072R08
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q074R01
[/TD]
[TD="bgcolor: #FFFF00"]
Q069R01
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q074R01
[/TD]
</tbody>
As you can see in the first line Q010R02 = Q069R01 and 2 lines from the end you can see Q069R01 = Q072R08 and in the last tine Q072R08 = Q074R01 so those 2 last equalities mean that Q010R02 = Q069R01 = Q072R08 = Q074R01 (there are 4 equality here). So this line of equality is the only one that we need ....
So if I tag the lines that are equals :
<tbody>
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q069R01
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q072R08
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q074R01
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: #A9D08E"]
Q010R12
[/TD]
[TD="bgcolor: #A9D08E"]
Q036R15
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q020R44
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q022R42
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R71
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q022R26
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q010R02
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
equals to Q010R02
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q072R08
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
equals to Q010R02
[/TD]
[TD="bgcolor: #B4C6E7"]
Q069R01
[/TD]
[TD="bgcolor: #B4C6E7"]
Q074R01
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
equals to Q010R02
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q069R01
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
equals to Q010R02
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q010R02
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
equals to Q010R02
[/TD]
[TD="bgcolor: #FFFF00"]
Q072R08
[/TD]
[TD="bgcolor: #FFFF00"]
Q074R01
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
equals to Q010R02
[/TD]
</tbody>
The result expected should be like that :
<tbody>
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q069R01
[/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q072R08
[/TD]
[TD="bgcolor: #DBDBDB"]
Q010R02
[/TD]
[TD="bgcolor: #DBDBDB"]
Q074R01
[/TD]
[TD="bgcolor: #A9D08E"]
Q010R12
[/TD]
[TD="bgcolor: #A9D08E"]
Q036R15
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q020R44
[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
Q022R42
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R71
[/TD]
[TD="bgcolor: #FCE4D6"]
Q021R34
[/TD]
[TD="bgcolor: #FCE4D6"]
Q022R26
[/TD]
</tbody>
Basically all equalities are in only one "group". And as you can see this table a lot easier to read.