|I must be missing something.|
Columns A and B in your Before & After look exactly the same, so nothing has to be done.
Columns C & D are sorted by Column D. (Select Columns C:D, Data...Sort...Sort by Column D)
Columns E & F are sorted by Column F. (Select Columns E:F, Data...Sort...Sort by Column F)
Those steps result in exactly the output that you've posted.
A B C D E F
1 1 X 2 X 1 X
2 2 Y 1 Y 3 Y
3 3 Z 3 Z 2 Z
I can also get the same results with INDEX(MATCH...)) formulas, but what is wrong with using Excel's built in Sort feature?
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.