## Count identical numbers in two columns but items must be in same row

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

Array formula in cell E2:

**How to enter an array formula**

- Select cell E2
- Paste the formula in formula bar
- Press and hold CTRL + SHIFT simultaneously
- Press Enter
- Release all keys

Your formula now begins and ends with a curly bracket, if you did it right.

Like this {=SUM((A2:A6=B2:B6)*1)}

### Explaining formula

**Step 1 - Compare values in column A with column B**

A2:A6=B2:B6

becomes

{12;8;22;7;14}={15;8;19;22;14}

and returns

{FALSE;TRUE;FALSE;FALSE;TRUE}

**Step 2 - Multiply boolean values with 1**

To be able to sum the values in this array {FALSE;TRUE;FALSE;FALSE;TRUE} we need to convert them to 0 and 1. FALSE = 0 and TRUE = 1.

(A2:A6=B2:B6)*1

becomes

({FALSE;TRUE;FALSE;FALSE;TRUE})*1

and returns

{0;1;0;0;1}

**Step 3 - Sum values in array**

SUM((A2:A6=B2:B6)*1)

becomes

SUM({0;1;0;0;1})

and returns 2.

This formula also works with text values, to remove blanks before and after use TRIM function.

### Download excel *.xlsx file

Count identical numbers in two columns but items must be in same row.xlsx

Count unique distinct values that meet multiple criteria

This post demonstrates how to build an array formula that counts unique distinct values based on criteria. What's on this […]

Count Conditionally Formatted cells

This article explains how to count cells highlighted with Conditional Formatting (CF). The image above shows data in cell range […]

This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are […]

Count cells between specified values

This article demonstrates formulas that calculate the number of cells between two values, the first scenario involves two search values […]

Count unique distinct values in two columns

Formula in C12: =SUM(1/COUNTIF($B$3:$B$8, $B$3:$B$8))+SUM(IF(COUNTIF($B$3:$B$8, $D$3:$D$8)=0, 1/COUNTIF($D$3:$D$8, $D$3:$D$8), 0)) How to create an array formula Double click on cell C12 […]

Count unique distinct values in a filtered Excel defined Table

This article demonstrates a formula that counts unique distinct values filtered from an Excel defined Table. Debra Dalgleish described in […]

How to count unique distinct values based on a date

The array formula in cell D3 calculates the number of unique distinct items based on the given date in column B. […]

Count unique distinct values within same week, month or year

The array formula in cell E3 counts unique distinct items for all dates within the same week. Example, week 2 […]

This article demonstrates formulas that count values in cell based on a delimiting character. The image above shows a formula […]

Count unique distinct values based on a condition

The following article demonstrates how to construct a formula that counts unique distinct values based on a condition. The image […]

### 3 Responses to “Count identical numbers in two columns but items must be in same row”

### Leave a Reply to Indigo

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

You can use non array formula, like this:

=SUMPRODUCT((A2:A6=B2:B6)*(A2:A6/B2:B6))

Try to find another non array formula.

There is a number of ways to make such a count as non array formula, e.g. =SUM(INDEX((A2:A6=B2:B6)*1,,)). But why not use array formula if it does the job?

[quote]Leonid says:

April 12, 2016 at 6:49 pm

There is a number of ways to make such a count as non array formula, e.g. =SUM(INDEX((A2:A6=B2:B6)*1,,)). But why not use array formula if it does the job?[/quote]

I suspect that Kidd has many more rows and columns in his file and CSE formulas are eating resources.