I need to count the number of matches between cells in two columns. The data in the cell are names. Unfortunately, some of the names contain an asterisk at the end, so they are not an exact match. Is there a way to count the number of rows that contain matches between the two cells of only the first 3 letters or so?

  • 1
    Using COUNTIF should do the trick. For example, looking in a range in column M for entries beginning with "AA" would be =COUNTIF(M1:M1000,"AA*") – PeterT Oct 3 '18 at 17:59
  • 1
    @PeterT Sounds like a good answer to me, why don't you post it? – cybernetic.nomad Oct 3 '18 at 18:26

Wildcards are tricky in some Excel formulas (and don't even look for using regular expressions!). For a simple count, however, using the COUNTIF function will work just fine. So if your data looks like this:

|    |  A  |
|  1 | AAA |
|  2 | AAB |
|  3 | AAC |
|  4 | ABA |
|  5 | ABB |
|  6 | ABC |
|  7 | ACA |
|  8 | ACB |
|  9 | ACC |
| 10 | ADA |

Then you can count the cells in the range starting with "AA" by using the formula


The wildcard indicator * is what matches multiple cells and counts them.


as an alternative, you could use sumproduct to do you counting. Since sumproduct performs array like calculations you want to avoid using full column references and restrict it to your actual range of data. In cell D2 I used the following formula and copied down:


This formula basically looks at the length you want to match and pulls only that many character from the left of the data you want to look through. It then compares that list with what you are looking for and generates a list of TRUE/FALSE. To convert TRUE/FALSE to 1 or 0, it needs to go through a math operation that does not change its value. In this case -- is being used, but +0, *1 could just as easily been used.



Similar to an earlier answer using SUMPRODUCT array but count comparing first three characters between cells per row ie A1 to B1, and A2 to B2 etc.


sum product left

another possible solution to your asterisk issue can be taken into account when matching the whole word but substituting out the asterisk. (asterisk is character 42).


enter image description here

This method does count empty cells as valid matches unless you add a further array to the SUMPRODUCT to count only if that the cell is not empty (less than or grater than empty).


this with a small tweek would then allow whole column calculations


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.