Excel: Pair things up between two columns (A and B), and show unpaired values in columns C and D

一笑奈何 提交于 2019-12-25 01:17:13

问题


Excel buffs:

There are many results showing up when searching for comparisons between two columns (ie: using VLOOKUP) but none of the results I have looked so far seems to do what I need in this particular way:

Column A has following values: Z, Q, V, V, T, T

Column B has following values: V, T, T, M

Column C will display Z, Q, V (here we have one V because one set of 'V' pairs up, leaving us with one unpaired 'V')

Column D will display M

The other examples I've seen so far assumes Column C will not have 'V' in it because it's already found in Column A, regardless of how many times it showed up.

Basically, instead, I need values between two columns paired up and removed, but leave me with any "odd ones" out.

I've been unable to figure this one out using formulae - I've resorted to sorting everything first, then shifting cells in either Column A or B downwards until Columna A and B either have matching values or odd one out in each row

Thanks in advance

Edit: Another way of saying it: I'd like to "eliminate" paired up values from Columns A and B, until all pairs have been removed, leaving me with remaining values in Column A and B


回答1:


Let's make the assumption that the answers in C/D are allowed to reside in the same row as the unmatched originals in A/B.

Here's the formula for C1, copy and paste it down:

=REPT(A1,
 MAX(0,MIN(1,COUNTIF($A:$A,A1)
 -COUNTIF($B:$B,A1)
 -IF(ROW()=1,0,COUNTIF(OFFSET($C$1,0,0,ROW()-1,1),A1))
 )))

Basically, we want to "repeat" the corresponding value in column A if we haven't found a match for it in B and we haven't already accounted for it in C so far.

There's logic in there to ensure that OFFSET() doesn't refer to a zero-height range, and that we repeat either 0 or 1 time, no more and no less, on each row of C.

The formula for D1 is similar, but reversed to compare B back to A:

=REPT(B1,
 MAX(0,MIN(1,COUNTIF($B:$B,B1)
 -COUNTIF($A:$A,B1)
 -IF(ROW()=1,0,COUNTIF(OFFSET($D$1,0,0,ROW()-1,1),B1))
 )))


来源:https://stackoverflow.com/questions/12333780/excel-pair-things-up-between-two-columns-a-and-b-and-show-unpaired-values-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!