Find most common letter in string

SteveWright

New Member
Joined
Aug 26, 2009
Messages
44
Hi guys. I'm looking to write a formula (not macro if possible) that looks for the most common letter in a string.

Lets suppose cell A1 = aaabb then the formula would return "a".

I've been messing around with code() and mode() but cant seem to write one formula to complete this job.

I have a UDF allready written, but its quite slow.

Many thanks,
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try the following formula, which needs to be confirmed with CONTROL+SHIFT+ENTER...

=CHAR(MODE(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))))

Note that if there's two or more letters tied for the most common letter, the formula returns the first letter that occurs in the text string.
 
Upvote 0
Genius,

Thanks.

<< Exactly what I'm looking for - and it works great.

I added in SUBSTITUTE(A1," ","") to remove space in A1 to allow me to add sentences.

Being a theorist - anyone have a stab at explain how the formula works?

Cheers
Glen
 
Upvote 0
Another option, for a Unicode character:

=MID(A1,MATCH(MAX(LEN(A1)-LEN(SUBSTITUTE(A1,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),""))),LEN(A1)-LEN(SUBSTITUTE(A1,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),"")),0),1)

... confirmed with CSE

In case of tie returns the first one.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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