Counting text in a range that may appear multiple times in a cell

AnnaBanana4

New Member
Joined
Sep 22, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
I'm looking to find a way to count the number of occurrences of text in a range, including multiples in the same cell.

For example, I have this:
1663871023576.png


To count "101"s in the list, I have this formula in D2: =COUNTIF(A$2:A$7,"*"&$C2&"*")
But this formula doesn't seem to take into account multiples in the same line. As well, I have no idea why "106" isn't counting.

Is there a way to do this in excel without VBA?

Thanks in advance!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Enter the following formula in D2, and copy...

Excel Formula:
=SUMPRODUCT(LEN($A$2:$A$6)-LEN(SUBSTITUTE($A$2:$A$6,C2,"")))/LEN(C2)

By the way, in future, please post your data as text or use the add-in xl2BB. Then people here can easily copy and paste the data onto their worksheet in order to come up with a solution and test. ;)

Hope this helps, cheers!
 
Upvote 0
Solution
Enter the following formula in D2, and copy...

Excel Formula:
=SUMPRODUCT(LEN($A$2:$A$6)-LEN(SUBSTITUTE($A$2:$A$6,C2,"")))/LEN(C2)

By the way, in future, please post your data as text or use the add-in xl2BB. Then people here can easily copy and paste the data onto their worksheet in order to come up with a solution and test. ;)

Hope this helps, cheers!
Thanks! It works!

And, yes, will not be posting pictures of data in the future.
 
Upvote 0
Ack! Follow up problem.

ListItemCount
1201 1201 1201 1103 1105 1105 1202 1202 1202 1205 12051012
1201 1201 1201 1101 11011020
1031
2016
2023
2030
11012
11020
11031
12016
12023
12030

Is there a way to differentiate between numbers with other numbers within it? For example, above, 1201 is being counted as "201" as well, but I don't want that.

Thanks!
 
Upvote 0
In that case, try...

annabanana v2.xlsm
ABC
1ListItemCount
21201 1201 1201 1103 1105 1105 1202 1202 1202 1205 12051010
31201 1201 1201 1101 11011020
41030
52010
62020
72030
811012
911020
1011031
1112016
1212023
1312030
Sheet1
Cell Formulas
RangeFormula
C2:C13C2=SUMPRODUCT(--(FILTERXML("<root><item>"&TEXTJOIN("</item><item>",TRUE,SUBSTITUTE($A$2:$A$3," ","</item><item>"))&"</item></root>","//item")=B2))
 
Upvote 0
Although, I think it would be more efficient to define a name with the FILTERXML part of the formula, and then use that name in your worksheet formula. For example, first define the following name (Ribbon >> Formulas >> Name Manager)...

Code:
Name:  MyItems

Refers to:  =FILTERXML("<root><item>"&TEXTJOIN("</item><item>",TRUE,SUBSTITUTE($A$2:$A$4," ","</item><item>"))&"</item></root>","//item")

Then enter the following worksheet formula in C2, and copy down:

Code:
=SUMPRODUCT(--(MyItems=B2))
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,485
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top