Joshua Frommer
Joshua Frommer

Reputation: 3

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

Upvotes: 0

Views: 468

Answers (2)

bzimor
bzimor

Reputation: 1628

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 |   |   |   |

Upvotes: 1

Tom Sharpe
Tom Sharpe

Reputation: 34230

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 CtrlShiftEnter

Upvotes: 0

Related Questions