Function/formula to count text string with wildcard in single cell

Tigerexcel

Active Member
Joined
Mar 6, 2020
Messages
493
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Does anyone know a way of counting the number of occurrences of a string with a wildcard within a single cell using a function, array or formula?

MEB Student Performance (2).xlsx
A
1ABC2020:P:57, ABC2040:P:53, ABC2050:P:58, ABC2080:N:48,
Sheet1


I would like to find the number of times ABC2*P* occurs, which in this case is 2. A combination of LEN and SUBSTITUTE seems to work if the desired text string does not contain a wildcard but I can't get anything to work when there's a wildcard involved.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try

=SUM(ISNUMBER(SEARCH($D$2,REPLACE(A2,15,99,""),1)),ISNUMBER(SEARCH($D$2,REPLACE(A2,29,99,""),15)),ISNUMBER(SEARCH($D$2,REPLACE(A2,43,99,""),29)),ISNUMBER(SEARCH($D$2,A2,43)))

D2 = ABC2*P

1595508021882.png
 
Upvote 0
This allows for up to 10 9 per cell. It appears fro your samples (here & in previous threads) that there is always 8 characters before the P/N/HD etc

20 07 23.xlsm
ABC
1ResultsCountFormula should return
2ABC2020:P:57, ABC2040:P:53, ABC2050:P:58, ABC2080:N:48, 33
3ABC2020:P:50, ABC2040:P:54, ABC2050:N:34, ABC2080:N:9, 22
4ABC2020:P:56, ABC2040:N:48, ABC2050:N:48, ABC2080:N:44, 11
5ABC2020:C:63, ABC2040:N:36, ABC2050:N:43, 00
6ABC2020:D:76, ABC2040:P:55, ABC2050:C:67, 11
7ABC2020:D:72, ABC2040:P:52, ABC2050:P:52,22
8ABC1010:D:75, ABC1020:C:69, ABC1110:HD:80, ABC2100:P 57, 11
Count in Cell
Cell Formulas
RangeFormula
B2:B8B2=SUMPRODUCT(--(LEFT(TRIM(MID(SUBSTITUTE(", "&A2,", ",REPT(" ",100)),{1,2,3,4,5,6,7,8,9}*100,100)),4)="ABC2"),--(MID(TRIM(MID(SUBSTITUTE(", "&A2,", ",REPT(" ",100)),{1,2,3,4,5,6,7,8,9}*100,100)),9,1)="P"))
 
Last edited:
Upvote 0
just for fun

note: my solution doesn't care how many elements are there, just counting :biggrin:
 
Upvote 0
It appears from your samples (here & in previous threads) that there is always 8 characters before the P/N/HD etc
If that is so, a simpler formula would be

20 07 23.xlsm
AB
1ResultsCount
2ABC2020:P:57, ABC2040:P:53, ABC2050:P:58, ABC2080:N:48, 3
3ABC2020:P:50, ABC2040:P:54, ABC2050:N:34, ABC2080:N:9, 2
4ABC2020:P:56, ABC2040:N:48, ABC2050:N:48, ABC2080:N:44, 1
5ABC2020:C:63, ABC2040:N:36, ABC2050:N:43, 0
6ABC2020:D:76, ABC2040:P:55, ABC2050:C:67, 1
7ABC2020:D:72, ABC2040:P:52, ABC2050:P:52,2
8ABC1010:D:75, ABC1020:C:69, ABC1110:HD:80, ABC2100:P 57, 1
9ABC2020:N:40, ABC1111:P:550
Count in Cell
Cell Formulas
RangeFormula
B2:B9B2=COUNT(1/(LEFT(REPLACE(TRIM(MID(SUBSTITUTE(", "&A2,", ",REPT(" ",100)),{1,2,3,4,5,6,7,8,9}*100,100)),5,4,""),5)="ABC2P"))
 
Upvote 0
Thanks Gaz, Peter and Sandy. I spent a good deal of time today trying to come up with a formula and was unsuccessful, almost thought it couldn't be done via a formula. I won't pretend that I understand the formulae completely but at this stage it's easier to enter that on other users' spreadsheet rather than explaining PQ to them.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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