What I have: two columns of text data, that are given to contain only distinct (no duplicate) items.
What I want: The second column sorted such that corresponding items are aligned in the same rows. If the first column contains an item with no match in the second column, that row is left blank in the second column. If the second column contains items with no match in the first, all such items are appended below the last row of the first column. While not required, feel free to assume the first column is sorted alphabetically.
Example
Before After
Col1 Col2 Col1 Col2
A Q A A
B E B B
C B C
D W D
E A E E
Q
W
This small example is quite easy to do by eyeball, but my data may contain from a few hundred to about two thousand items.
Thanks in advance.
There’s no practical way to do this in 1 step with a formula exactly as you want.
You CAN do it, but it would be so much obfuscated
INDEX/ROWstuff that it’s not readable.Are you able to separate it into multiple steps, or do transformations after excel? Depending on what your context is, different
solutions will be more practical than others.
Assuming your sheet is like:
I can do it in 3 added columns:
C2)="0"&IFERROR(VLOOKUP(A2,$B:$B,1,FALSE),"").D2)=IF(ISNA(VLOOKUP(B2,$A:$A,1,FALSE)),"1"&B2,"")Cbefore columnD, with formula inE2:=IF(ROW(E2)<=COUNTA(C:C),C2,INDEX(D:D,ROW(E2)-COUNTA(C:C)+1)). Note that the +1 is because I assume there’s a column header.This results in:
Now you can copy/paste as text column E somewhere, sort it, and remove the 1st char. Adding the
0and1allows column E to be sorted in this way. If you don’tdo it this way, you won’t be able to discriminate between “removing blanks” and the desirable blank rows.
That’s a lot of steps to do this; you may consider writing a macro to do it if you need to automate this more.