## Extract shared values between two columns

This article demonstrates ways to extract shared values in different cell ranges, two and three cell ranges. The Excel 365 formulas are smaller and easier to understand.

#### Table of Contents

## 1. Extract shared values between two columns

**Question:**How can I compare two columns to find values that exist in both cell ranges?

The picture above shows two lists, one in column B and one in column D. The array formula in cell F3 extracts values that both lists have.

Array formula in cell F3:

In this case GG, HH, II, and JJ are in both lists, see the picture below.

The formula above can only compare two columns, however, the lists don't have to be the same size.

If you need to compare two different multicolumn cell ranges, read the following article:

Recommended articles

The image above shows an array formula in cell B12 that extracts values shared by cell range B2:D4 (One) and […]

### 1.1 How to create an array formula

- Select cell F3
- Press with left mouse button on in formula bar

- Copy and paste the array formula above to formula bar
- Press and hold Ctrl + Shift simulateously
- Press Enter
- Release all keys

You can check using the formula bar that you did above steps right, excel tells you if a cell contains an array formula by surrounding the formula with a beginning and ending curly brackets, like this: {=array_formula}.

Don't enter these characters yourself they show up automatically if you did above steps correctly.

Recommended articles

Array formulas allows you to do advanced calculations not possible with regular formulas.

**1.2 How to copy array formula**

Copy cell F3 and paste it to cells belowÂ as far as needed.

### 1.3 Explaining array formula in cell C2

You can easily examine a formula (or array formula) that you don't understand, select the cell containing the formula. Go to tab "Formulas", press with left mouse button on "Evaluate Formula".

The "Evaluate" button above lets you see the next "calculation" step.

#### Step 1 - Compare cell range 1 with cell range 2

The COUNTIF function lets you compare values if you enter it as an array formula and use multiple values as criteria.Â COUNTIF(range, criteria)

COUNTIF($D$3:$D$12, $B$3:$B$12)

becomes

COUNTIF({"GG"; "HH"; "II"; "JJ"; "KK"; "LL"; "MM"; "NN"; "OO"; "PP"}, {"AA"; "BB"; "CC"; "DD"; "EE"; "FF"; "GG"; "HH"; "II"; "JJ"})

and returns

{0; 0; 0; 0; 0; 0; 1; 1; 1; 1}

The array is shown in column H below.

This tells us that AA exists 0 (zero) times in cell range D3:D12,

BB - 0, CC - 0, DD - 0, EE-0, FF - 0

but GG is found once in cell range D3:D12 and so are HH, II, JJ.

Recommended articles

Counts the number of cells that meet a specific condition.

#### Step 2 - Check if value exists, if so return corresponding position in array

IF({0; 0; 0; 0; 0; 0; 1; 1; 1; 1}, MATCH(ROW($B$3:$B$12),ROW($B$3:$B$12)), "")

becomes

IF({0; 0; 0; 0; 0; 0; 1; 1; 1; 1}, {1; 2; 3; 4; 5; 6; 7; 8; 9; 10}, "")

and returns

{""; ""; ""; ""; ""; ""; 7; 8; 9; 10}

The array is shown in column H below.

Recommended articles

Checks if a logical expression is met. Returns a specific value if TRUE and another specific value if FALSE.

#### Step 3 - Extract k-th smallest value

Until now we have been working with an array of values but excel allows us to only display one value per cell (*That is not entirely true, as of Excel 2016 you can display all values in an array in one cell*)

To extract a specific number from an array I use the SMALL function.

SMALL(IF(COUNTIF($D$3:$D$12, $B$3:$B$12), MATCH(ROW($B$3:$B$12),ROW($B$3:$B$12)), ""), ROWS($A$1:A1))

becomes

SMALL({""; ""; ""; ""; ""; ""; 7; 8; 9; 10}, ROWS($A$1:A1))

becomes

SMALL({""; ""; ""; ""; ""; ""; 7; 8; 9; 10}, 1)

and returns number 7, SMALL function ignores blanks and letters.

Recommended articles

The SMALL function lets you extract a number in a cell range based on how small it is compared to the other numbers in the group.

#### Step 4 - Return corresponding value

INDEX($B$3:$B$12, SMALL(IF(COUNTIF($D$3:$D$12, $B$3:$B$12), MATCH(ROW($B$3:$B$12),ROW($B$3:$B$12)), ""), ROWS($A$1:A1)))

becomes

INDEX($B$3:$B$12, 7)

becomes

INDEX({"AA"; "BB"; "CC"; "DD"; "EE"; "FF"; "GG"; "HH"; "II"; "JJ"}, 7)

and returns GG in cell F3.

When you copy cell F3 and paste it to cell F4 the relative cell references changes.Â ROWS($A$1:A1) becomesÂ ROWS($A$1:A2) and returns 2 in cell F4.

The second smallest value is then extracted from the array which is 8. The value in cell range B3:B12 in row 8 is HH. HH is returned the value returned to F4.

Recommended articles

Gets a value in a specific cell range based on a row and column number.

### Get excel sample file for this tutorial

common-values1.xlsx

(Excel 2007Â Workbook *.xlsx and later versions)

## 2. Extract shared values between two columns - Excel 365

This Excel 365 dynamic array formula extracts values from cell range B3:B12 only if they also exist in cell range D3:D12.

Formula in cell F3:

### 2.1 Explaining formula

#### Step 1 - Find values in common

The COUNTIF function lets you compare values if you enter it as an array formula and use multiple values as criteria.

COUNTIF(*range*, *criteria*)

COUNTIF($D$3:$D$12, $B$3:$B$12)

becomes

COUNTIF({"GG"; "HH"; "II"; "JJ"; "KK"; "LL"; "MM"; "NN"; "OO"; "PP"}, {"AA"; "BB"; "CC"; "DD"; "EE"; "FF"; "GG"; "HH"; "II"; "JJ"})

and returns

{0; 0; 0; 0; 0; 0; 1; 1; 1; 1}

COUNTIF($D$3:$D$12, $B$3:$B$12)

#### Step 2 - Extract values

The FILTER function extractsÂ values/rows based on a condition or criteria.

FILTER(*array*,Â *include*, [*if_empty*])

FILTER($B$3:$B$12,COUNTIF($D$3:$D$12, $B$3:$B$12))

becomes

FILTER($B$3:$B$12, {0; 0; 0; 0; 0; 0; 1; 1; 1; 1})

and returns

{"GG"; "HH"; "II"; "JJ"}

## 3. Extract shared values between two columns - case sensitive

This formula shown in the image above extracts values in the first cell range if they also exist in the second cell range, upper and lower letters are also evaluated.

Excel 365 dynamic array formula in cell F3:

### 3.1 Explaining formula

#### Step 1 - Rearrange values from vertical to horizontal

The TRANSPOSE function converts a vertical range to a horizontal range, or vice versa.

TRANSPOSE(*array*)

TRANSPOSE(D3:D12)

becomes

TRANSPOSE({"GG"; "HH"; "II"; "JJ"; "KK"; "LL"; "MM"; "NN"; "OO"; "aa"})

and returns

{"GG", "HH", "II", "JJ", "KK", "LL", "MM", "NN", "OO", "aa"}.

#### Step 2 - Compare values based on upper and lower letters

The EXACT function performs a case sensitive comparison between values.

EXACT(*value1*, *value2*)

EXACT(B3:B12,TRANSPOSE(D3:D12))

becomes

EXACT(B3:B12,{"GG", "HH", "II", "JJ", "KK", "LL", "MM", "NN", "OO", "aa"})

becomes

EXACT({"AA"; "BB"; "CC"; "DD"; "EE"; "FF"; "gg"; "HH"; "II"; "JJ"}, {"GG", "HH", "II", "JJ", "KK", "LL", "MM", "NN", "OO", "aa"})

and returns an array shown in the image below. I have added the corresponding values from both cell ranges and highlighted values that exist in both cell ranges.

#### Step 3 - Convert boolean values

The asterisk lets you multiply numbers in an Excel formula, it also lets you convert boolean values to their numerical equivalents.

TRUE -> 1

FALSE -> 0 (zero)

EXACT(B3:B12,TRANSPOSE(D3:D12))*1

becomes

{FALSE,FALSE,FALSE, ... ,FALSE}*1

and returns

#### Step 4 - Create an array containing 1's

The ROW function returns the corresponding row number in a cell reference or multiple row numbers if a cell range reference is used.

ROW(*reference*)

ROW(B3:B12)^0

becomes

{3; 4; 5; 6; 7; 8; 9; 10; 11; 12}^0

and returns

{1; 1; 1; 1; 1; 1; 1; 1; 1; 1}.

#### Step 5 - Sum numbers row-wise

The MMULT function calculates the matrix product of two arrays, an array as the same number of rows as array1 and columns as array2.

MMULT(array1, array2)

MMULT(EXACT(B3:B12,TRANSPOSE(D3:D12))*1,ROW(B3:B12)^0)

becomes

MMULT({0,0,0, ... ,0},{1; 1; 1; 1; 1; 1; 1; 1; 1; 1})

and returns

{0; 0; 0; 0; 0; 0; 0; 1; 1; 1}.

#### Step 6 - Filter values based on array

The FILTER function extractsÂ values/rows based on a condition or criteria.

FILTER(*array*,Â *include*, [*if_empty*])

FILTER($B$3:$B$12,MMULT(EXACT(B3:B12,TRANSPOSE(D3:D12))*1,ROW(B3:B12)^0))

becomes

FILTER($B$3:$B$12, {0; 0; 0; 0; 0; 0; 0; 1; 1; 1})

and returns

{"HH"; "II"; "JJ"}.

## 4. Filter common values from three separate columns

The image above demonstrates a formula in cell B15 that extracts values if they exist in all three cell ranges B3:B12, D3:D12, and F3:F12.

Array formula in B15:

Copy cell B15 and paste it to cells below as far as necessary.

To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.

The formula bar now shows the formula with aÂ beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

### Explaining formula in cell B15

#### Step 1 - Prevent duplicates in the list

TheÂ COUNTIF functionÂ counts values based on a condition or criteria.Â The first argumentÂ $B$14:B14Â expands as the cell is copied to cells below. This makes the formula aware of displayed values above the current cell.

COUNTIF($B$14:B14, $B$3:$B$12)

becomes

COUNTIF("Common values in three columns", {"AA"; "BB"; "CC"; "DD"; "EE"; "FF"; "GG"; "HH"; "GG"; "JJ"})

and returns

{0;0;0;0;0;0;0;0;0;0}

#### Step 2 - Find position of value in array

The MATCH function returns a number representing the position of a value in a list.

MATCH(0,COUNTIF($B$14:B14,$B$3:$B$12)+(((COUNTIF($D$3:$D$11,$B$3:$B$12)>0)+(COUNTIF($F$3:$F$12,$B$3:$B$12)>0))<>2),0)

becomes

MATCH(0,C{0;0;0;0;0;0;0;0;0;0}+((({TRUE;FALSE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE})+({FALSE;TRUE;TRUE;FALSE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE}))<>2),0)

becomes

MATCH(0,{1;1;0;1;1;1;0;1;0;1},0)

and returns 3.

#### Step 3 - Return value

The INDEX function returns a value based on a row and column number.

INDEX($B$3:$B$12, MATCH(0, COUNTIF($B$14:B14, $B$3:$B$12)+IF(((COUNTIF($D$3:$D$11, $B$3:$B$12)>0)+(COUNTIF($F$3:$F$12, $B$3:$B$12)>0))=2, 0, 1), 0))

becomes

INDEX($B$3:$B$12, 3)

and returns "CC" in cell B15.

### Get Excel *.xlsxÂ file

### Compare category

Array formula in B15: =INDEX($B$3:$B$12, MATCH(0, COUNTIF($B$14:B14, $B$3:$B$12)+IF(((COUNTIF($D$3:$D$11, $B$3:$B$12)>0)+(COUNTIF($F$3:$F$12, $B$3:$B$12)>0))=2, 0, 1), 0)) Copy cell B15 and paste it to […]

This article shows how to compare two nonadjacent cell ranges and extract values that exist only in one of the […]

How would you figure out an unique list where the sum of in one column doesn't match the other column? […]

The image above demonstrates an array formula in cell B11 that extracts values that only exist in List 1 (B3:B7) […]

I will in this blog post demonstrate a formula that extracts common records (shared records) from two data sets in […]

This article explains how to extract values that exist in three different columns, they must occur in each of the […]

Overview Updating a list using copy/paste is a boring task.Â This blog article describes how to update values in a price […]

Today I am going to show you how to quickly compare two tables using Conditional Formatting (CF). I am going […]

This article demonstrates formulas that extract values that exist only in one column out of two columns. There are text […]

Question: How do i remove common values between two lists? Answer: The solution in this article, removes common values and […]

Question: i have two sets of data - one has an identifier column and one result column. A2 data1 B2 […]

The image above shows an array formula in cell B12 that extracts values shared by cell range B2:D4 (One) and […]

The formulas above extracts values that exists only in one or the other cell range, if you are looking for […]

In this example we are going to use two lists with identical columns, shown in the image above. It is […]

This article describes an array formula that compares values from two different columns in two worksheets twice and returns a […]

## Functions in this article

More than 1300 Excel formulas

## Excel formula categories

## Excel categories

### 15 Responses to “Extract shared values between two columns”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

If you need to expand your comparison you will need to highlight all the rows, in the column, where you want the common values stored. Paste the above equation into the formula box, may need to use F2 button, and change the values of 17 to however many rows you need. The "" portion of the equation will need retyped as "". Use CTRL + SHFT + ENTER to run comparison. This is due to the equation using an array. Good Luck

Thank you for your comment. I have edited the article.

hi oscar,

i have a small problem which is similar to the one you have illustrated above, with the only difference being that i have some duplicates within List1 and List2 themselves.

eg. GG is repeated twice in List1, HH is repeated thrice in List2.

when i use this formula, i get duplicate GG and HH in Column 3. is there a way to prevent them from appearing? i tried a mishmash of this formula and a couple of others that i learnt on your website (ones listed in Duplicate category), but to no avail.

please help me out; i will appreciate that very much.

much thanks and kind regards.

K. Yantri,

Use this array formula in cell C2:

hi oscar,

thank you for your kind help in this regard.

Hi,

I am trying to compare the values in the excel where i have got list of values in the Column A and List of Values in Column B.

I want to find all the duplicate values in Row 1 and Row 2 but when i am applying above formulas getting #Value! error.

Anoop,

How to create an array formula

1.Select cell C2

2.Press with left mouse button on formula bar

3.Copy Paste array formula

4.Press and hold Ctrl + Shift

5.Press Enter

Hi Oscar,

Thanks for your quick reply.

PSB the proper example of my prob:-

Question 1 How can we identify duplicate values from each column?

Question 2 If it is not possible to compare 4 column can we do it for 2?

Data 1 Data 2 Data 3 Data 4

1 5 9 11

2 6 10 12

3 4 4 4

4 7 7 7

5 8 8 8

Multi-nested formulas, as the one above, can be tough to decipher

The free/unlocked function syntax and usage navigation Add-in (link below) can speed-up your modelling work, if you are:

1) looking for multi-lingual documentation or translation for a function

2) searching for a new function to simplify your formulas

3) wondering, if a function is backwards compatible with previous Excel versions

https://www.spreadsheet1.com/syntax-and-usage-navigation-add-in-for-excel-2013-functions.html

Hi Oscar,

Need a formula to count identical numbers in two columns but items must be in same row (position).

12 15

8 8 good count 1

22 19

7 22 for 22 not count cause is not in same row

14 14 good count 2

....

....

Thanks.

[…] KiddÂ asks: […]

[…] { googletag.display('div-gpt-ad-1486744346002-0'); }); Hi have a look at How to find common values from two lists | Get Digital Help - Microsoft Excel resource that should do the […]

Thanks for such a good explanation.

Hi there! This is a great formula, how can I make sure it is case sensitive? Appreciate any info you can provide. Thanks

Jjoseph,

thank you! I have added a case sensitive formula to this article.