Solved

Extract initials from name while ignoring quotes

Posted on 2012-04-10
4
382 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
[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
  • Learn & ask questions
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:Ingeborg Hawighorst (Microsoft MVP / EE MVE)
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)))

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

696 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