Extract initials from name while ignoring quotes

Posted on 2012-04-10
Last Modified: 2012-06-27
I'm using this bit of code to extract initals from names:

=IF(LEN(B21)-LEN(SUBSTITUTE(B21," ",""))=0,LEFT(B21,1),IF(LEN(B21)-LEN(SUBSTITUTE(B21," ",""))=1,LEFT(B21,1)&MID(B21,FIND(" ",B21)+1,1),LEFT(B21,1)&MID(B21,FIND(" ",B21)+1,1)&MID(B21,FIND(" ",B21,FIND(" ",B21)+1)+1,1)))

Open in new window

It works fine for...

John Stevens = JS
John Robert Stevens = JRS

However, it returns quotation marks...

John "Ray" Stevens = J"S
John Ray "Stevens" = JR"

Can the formula ignore quotation marks?
Question by:mcnuttlaw

Accepted Solution

yawkey13 earned 400 total points
ID: 37830543
Replace each occurrence of "B21" with SUBSTITUTE(B21,"""","")

Here is the code for B1...
=IF(LEN(SUBSTITUTE(B1,"""",""))-LEN(SUBSTITUTE(SUBSTITUTE(B1,"""","")," ",""))=0,LEFT(SUBSTITUTE(B1,"""",""),1),IF(LEN(SUBSTITUTE(B1,"""",""))-LEN(SUBSTITUTE(SUBSTITUTE(B1,"""","")," ",""))=1,LEFT(SUBSTITUTE(B1,"""",""),1)&MID(SUBSTITUTE(B1,"""",""),FIND(" ",SUBSTITUTE(B1,"""",""))+1,1),LEFT(SUBSTITUTE(B1,"""",""),1)&MID(SUBSTITUTE(B1,"""",""),FIND(" ",SUBSTITUTE(B1,"""",""))+1,1)&MID(SUBSTITUTE(B1,"""",""),FIND(" ",SUBSTITUTE(B1,"""",""),FIND(" ",SUBSTITUTE(B1,"""",""))+1)+1,1)))
LVL 50

Assisted Solution

by:Ingeborg Hawighorst
Ingeborg Hawighorst earned 100 total points
ID: 37830558

not pretty, but works:

=IF(LEN(SUBSTITUTE(B21,"""",""))-LEN(SUBSTITUTE(SUBSTITUTE(B21,"""","")," ",""))=0,LEFT(SUBSTITUTE(B21,"""",""),1),IF(LEN(SUBSTITUTE(B21,"""",""))-LEN(SUBSTITUTE(SUBSTITUTE(B21,"""","")," ",""))=1,LEFT(SUBSTITUTE(B21,"""",""),1)&MID(SUBSTITUTE(B21,"""",""),FIND(" ",SUBSTITUTE(B21,"""",""))+1,1),LEFT(SUBSTITUTE(B21,"""",""),1)&MID(SUBSTITUTE(B21,"""",""),FIND(" ",SUBSTITUTE(B21,"""",""))+1,1)&MID(SUBSTITUTE(B21,"""",""),FIND(" ",SUBSTITUTE(B21,"""",""),FIND(" ",SUBSTITUTE(B21,"""",""))+1)+1,1)))

Open in new window

Alternatively, put this into C21:


Then change your original formula to evaluate C21 instead of B21:

=IF(LEN(C21)-LEN(SUBSTITUTE(C21," ",""))=0,LEFT(C21,1),IF(LEN(C21)-LEN(SUBSTITUTE(C21," ",""))=1,LEFT(C21,1)&MID(C21,FIND(" ",C21)+1,1),LEFT(C21,1)&MID(C21,FIND(" ",C21)+1,1)&MID(C21,FIND(" ",C21,FIND(" ",C21)+1)+1,1)))

Open in new window

cheers, teylyn

Author Comment

ID: 37830563
Thanks.  Makes for quite an ugly looking formula but it work.
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37830713
A shortened formula....before Barry sees this

=IFERROR(LEFT(B1,1),"")&IFERROR(IF(MID(B1,FIND(" ",B1)+1,1)="""",MID(B1,FIND(" ",B1)+2,1),MID(B1,FIND(" ",B1)+1,1)),"")&IFERROR(IF(MID(B1,FIND(" ",B1,FIND(" ",B1)+1)+1,1)="""",MID(B1,FIND(" ",B1,FIND(" ",B1)+1)+2,1),MID(B1,FIND(" ",B1,FIND(" ",B1)+1)+1,1)),"")

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question