Extract shared values between two columns

Copper Contributor

Hi everyone, 

 

I am trying to extract shared values between two columns. I found a post on another website that has a formula to use, but I am struggling to apply it to my dataset. Below is the formula. 

 

=INDEX($A$2:$A$11, SMALL(IF(COUNTIF($B$2:$B$11, $A$2:$A$11), MATCH(ROW($A$2:$A$11),ROW($A$2:$A$11)), ""), ROWS($A$1:A1)))

 

This only works between cells 2-11. I have tried changing the values in the formula to fit my target (column A has 119 values and column B has 193), but for some reason, all I get in return is #VALUE! 

 

I'm not sure what I'm doing wrong, but ideally, I'd like to compare all 119 values in column A with the 193 values in column B and return the shared values in column C, or wherever I enter the formula. I am also figuring out how to apply this with various column lengths since I have a lot of columns to compare, and they all have different lengths. 

 

Thank you in advance for your help! 

7 Replies

@MGreenfield 

It would help if you could upload your worksheet with some sample data in it. Please remove/mask any sensitive data before upload.  

@MGreenfield 

Formula assumes your data starts from the second row. You may expand your range with some gap, wrap formula with IFERROR and enter it in C2 as an array formula (Ctrl+Shift+Enter), like

=IFERROR(INDEX($A$2:$A$1100, SMALL(IF(COUNTIF($B$2:$B$1100, $A$2:$A$1100), MATCH(ROW($A$2:$A$1100),ROW($A$2:$A$1100)), ""), ROWS($A$1:A1))),"")

and drag it down till empty cells appear.

Alternative non-array formula could be with AGGREGATE and with using of dynamic ranges, but that's not critical.

@Kodipady 

 

Attached is the document I'm working on. Thanks for your help! 

@MGreenfield 

In A2 and B2 there are errors returned. If remove, formula in C2 works.

Amazing! Thank you so much for your help!! @Sergei Baklan 

@MGreenfield , you are welcome

@Sergei Baklan 

I have data in “A” column and input in “B” column and required result is in  ” C” column.
I already fond the result is in “E” Column. But this result needs to fix the corresponding raw of the A Column.