COUNTIF Partial Matching

Excel Tip #016

COUNTIF Partial Matching

There are many COUNT functions that are available in Excel. One of which is the COUNTIF() function. Let us see a more detailed use of it.

The use of COUNTIF() function - It is used to count the number of cells in a given range which meets the specified condition. Its syntax is,

=COUNTIF(range,criteria)

The range field is the group of cells that you want to count. The criteria field tells the cells that needs to be counted which can be a number, expression, cell reference, or text string.

Consider the below example.
Example - COUNTIF() function

  • =COUNTIF(A2:A6,"Cadbury") - This gives me 1 as the result
  • =COUNTIF(A2:A6.A5) - In A5 we have Toblerone and the function searches for Toblerone in the list which is 1
  • =COUNTIF(B2:B6,23) - Here Mars chocolate has 23 and the result will be 1
  • =COUNTIF(B2:B6.">50") - The condition is to count cells which are above 50. We have Toblerone and Ferrero Rocher have quantity 61 & 87. Hence the result will be 2
  • =COUNTIF(A2:A6,"*") - Counts the number of cells containing any text in cells A2 through A6. The asterisk (*) is used as the wildcard character to match any character. The result is 5

Now since we have seen the use of asterisk (*), the wildcard character, let us now see how this can be used for Partial Matching.

Example - COUNTIF() Partial Matching
You may find that there are many situations where you need to count the number of cells in a range that only partially match your criterion.

By adding asterisks to the beginning and end of your criteria, for example, =COUNTIF(A2:A15,"*Cadbury*") will count all cells that include the word 'Cadbury' anywhere within the cell.

For the formula, =COUNTIF(A2:A15,"*Cadbury*") the result will be 6 since there are 6 rows of data with the word Cadbury irrespective of what the data is before and after the word.

We can use this partial matching technique to find the words which are with spaces too. For example let us take the word Kat only in "Kit Kat"

=COUNTIF(A2:A15,"*Kat*"), will give me result 3.

Hope this is a useful tip and can be used effectively for counting the cells being partially matched.

Comments

Popular posts from this blog

VLOOKUP - Exact Match & Approximate Match

Row 1 Is Missing. How to unhide?

Search Backwards in Excel