简体   繁体   中英

find duplicates in two columns and extract them to a new column

I have two columns with different lengths contains numbers like the following:

column 1  column 2

1          8
2          9
20         1
4          2
5          20 
6         

what I want to do is find the duplicates in the two columns and place them in a new column like the following:

column 1  column 2  column 3

1          8          1
2          9          2
20         1         20
4          2
5          20 
6        

so is there any way that I can get this result in excel?

Thanks in advance!

This should do it.

For you with Columns A and B:

=IF(ISERROR(MATCH(A1,$B$1:$B$5,0)),"",A1)

If your B range extends beyond 5, just change $5 to whatever the last row is, so $40 if 40 rows. If you have headers in Row 1, change A1 to A2 and $B$1 to $B$2.

Copy the formula into C1:C6 or whatever the length of A is. (A doesn't have to be longer than B, you just need the formula to span one column, and the match target to span the other).

From there, you can copy the data as values to D and sort Ascending to remove the empty cells and do with that what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM