 # How do I count how many text entries in column A match the entry in column B

I’ve tried constructs like COUNTIF(A1:A5, EXACT(A1,B1)) but nothing seems to work…

Update 1: I’ve added an example:

``````| A | B |

| X | X | --> 1
| X | Y |
| Y | Y | --> 2
| Y | Z |
| Z | Z | --> 3
``````

Here, it should return 3

`=COUNTIF(A1:A100;B1)` For to only count exact matching, check the option “Search criteria = and <> must apply to whole cells” in Tools > Options > Calc > Calculate.

If you have continuous data and column B contains a classification with increasing boundaries, the function FREQUENCY might work as well. [ lower boundary < class <= upper boundary ]

I tried this (and again, using your exact syntax) and it simply doesn’t work I understood that the asker has two columns and wants to find how many rows have matching entries, between those columns. If column A contains, say, potato, turnip, and carrot, and column B contains potato, broccoli, and carrot, then you’d want the value 2.

The normal thing to do in this situation is to create a third column that has a comparison formula on every row, and then count the matches. You first enter =IF(A1=B1;1;0) into C1. Then you select the cells you need in column C and use Edit > Fill > Down. This copies the formula and changes it to suit every row. Then you put something like =SUM(C1:C100) somewhere to count how many rows match. You can hide the third column if you think it looks messy.

Another way to do this, without the extra column, would be to write a macro function. Depending on how versatile you’d want the function to be, it could be quite short or tens of lines long.

Extra tip: if you want more powerful tools to manipulate that third column I mentioned, you may want to learn about array functions.

Thanks! I was hoping to avoid extra columns though, it seemed a simple enough request :-/ For example, conditional formatting can compare columns this way and highlight the mismatches, so I figured counting would be doable to…

The following seems to work, using array functions. For the cell value, type:

``````=SUM(A1:A5=B1:B5)
``````

and then hit `Ctrl-Shift-Enter` to submit it as an array function.

Strangely, adding a space before and after the `=` sign breaks it…