Solved

# Extract initials from name while ignoring quotes

Posted on 2012-04-10
379 Views
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)))
``````

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
Question by:mcnuttlaw
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

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)))
0

LVL 50

Assisted Solution

Ingeborg Hawighorst (Microsoft MVP / EE MVE) 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)))
``````

Alternatively, put this into C21:

=SUBSTITUTE(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)))
``````

cheers, teylyn
0

LVL 2

Author Comment

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

LVL 43

Expert Comment

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

Question has a verified solution.

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

### Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
###### Suggested Courses
Course of the Month6 days, 21 hours left to enroll