简体   繁体   中英

Compare data in two columns and print difference in 3rd column

In excel I am looking to do the following:

If a value in "Column B" exists anywhere in "Column A", print said value to "Column C"

and

If a value exists in "Column B" and does not exist in "Column A", print said value to "Column D"

So..

In a sheet where,

"Column A" has: 1, 2, 3, 4

"Column B" has: 1, 3, 5

I want,

"Column C" to populate " 1 " and " 3 "

"Column D" to populate " 5 "

- A     B     C     D
- 1     1     1     5
- 2     3     3
- 3     5
- 4

Simply use IF() formula and fill down:

 | A | B |                    C                                |                          D                          |
1| 1 | 1 |=IF(COUNTIF($A$1:$A$4,B1)>0,IF(ISBLANK(B1),"",B1),"")|=IF(COUNTIF($A$1:$A$4,B1)=0,IF(ISBLANK(B1),"",B1),"")|
2| 2 | 3 |
3| 3 | 5 |
4| 4 |   |

Then result will be like this:

 | A | B | C | D |
1| 1 | 1 | 1 |   |
2| 2 | 3 | 3 |   |
3| 3 | 5 |   | 5 |
4| 4 |   |   |   |

If you want them to appear without spaces, try

=IFERROR(INDEX($B$1:$B$3,SMALL(IF(COUNTIF($A$1:$A$5,$B$1:$B$3),ROW($B$1:$B$3)),ROW())),"")

and

=IFERROR(INDEX($B$1:$B$3,SMALL(IF(COUNTIF($A$1:$A$5,$B$1:$B$3)=0,ROW($B$1:$B$3)),ROW())),"")

Both of these are array formulae and must be entered with Ctrl Shift Enter

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