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

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

gaz_chops

Well-known Member
Joined
Apr 29, 2003
Messages
6,468
Platform
MacOS
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,193
Office Version
365
Platform
Windows
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:

gaz_chops

Well-known Member
Joined
Apr 29, 2003
Messages
6,468
Platform
MacOS
Note: my solution only allows for 4 per cell.
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,778
just for fun

note: my solution doesn't care how many elements are there, just counting :biggrin:
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,193
Office Version
365
Platform
Windows
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"))
 

Tigerexcel

Active Member
Joined
Mar 6, 2020
Messages
379
Office Version
2016
Platform
Windows
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.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,193
Office Version
365
Platform
Windows
You're welcome. Glad we could help. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,102,353
Messages
5,486,367
Members
407,542
Latest member
Tyronaught

This Week's Hot Topics

Top