Solved

Extract initials from name while ignoring quotes

Posted on 2012-04-10
4
364 Views
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?
0
Comment
Question by:mcnuttlaw
4 Comments
 
LVL 6

Accepted Solution

by:
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)))
0
 
LVL 50

Assisted Solution

by:teylyn
teylyn earned 100 total points
ID: 37830558
Hello,

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:

=SUBSTITUTE(B21,"""","")

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
0
 
LVL 2

Author Comment

by:mcnuttlaw
ID: 37830563
Thanks.  Makes for quite an ugly looking formula but it work.
0
 
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)),"")
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now