Count certain characters in one cell

Flashmus

New Member
Joined
Jan 4, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hey!

Would like some help with counting certain characters in a one cell.

3312221133111

1. Would like to count certain character combination in the string above. The combination I would like to search for is how many times "11" appears.
For me is should be 3 times. First 11 then the 111 contains "11" two times.

"11" = 3 times
"22" = 2 times
"33" = 2 times

2. Would also try to count occurrences of "1". It should count just one time even tho its a single(1), double(11) or tripple(111) and so on.
Here I would like it to count 3 in the string above.

1 = 3 times
2 = 1 time
3 = 2 times
 
Hi,
as an alternative solution

111.png


Cell D3
VBA Code:
=LET(a,MID(B2,SEQUENCE(LEN(B2)),2),b,REPT(SORT(UNIQUE(MID(B2,SEQUENCE(LEN(B2)),1))),2),HSTACK(b,MAP(b,LAMBDA(x,SUM(--(a=x))))))

Cell J3
Code:
=LET(a,MID(B2,SEQUENCE(LEN(B2)),1),b,FILTER(a,1=SCAN(1,SEQUENCE(LEN(B2)),LAMBDA(x,y,IF(y=1,x,IF(INDEX(a,y-1)=INDEX(a,y),x+1,1))))),c,SORT(UNIQUE(a)),HSTACK(c,MAP(c,LAMBDA(x,SUM(--(b=x))))))
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Solution found by Phouc, THX!
1. =SUMPRODUCT((MID(A1;SEQUENCE(LEN(A1));2)="11")*1)

2. =SUMPRODUCT((MID(A1;SEQUENCE(LEN(A1));1)="1")*(MID(A1&" ";SEQUENCE(LEN(A1))+1;1)<>"1"))

Havent tried the solution by 52779
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
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