Solved

Extract First and Last name from a string in a cell.  Hope there is a function in EXCEL to do this

Posted on 2014-09-04
8
185 Views
Last Modified: 2014-09-04
I have a string value in a cell from Active Directory.  In a recent question I was able to extract the full name from this string

CN=John Doe,CN=Users,DC=mydomain,DC=int     Using this function.  =MID(A1,4,FIND(",",A1)-4).   And it works great.  

Now I would like to extract the first name and last name, each in its own cell.  In other words, "John" in the B1cell and "Doe" in the C1 cell.  This way I can import to a database table.  Any help is greatly appreciated.
0
Comment
  • 4
  • 3
8 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40304932
This will work if there are only two names (no middle names or initials):
B1: =LEFT(MID(A1,4,FIND(",",A1)-4),FIND(" ",MID(A1,4,FIND(",",A1)-4))-1)
C1: =MID(MID(A1,4,FIND(",",A1)-4),FIND(" ",MID(A1,4,FIND(",",A1)-4))+1,100)

-Glenn
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40304933
What if the name is "John Burdon Sanderson Haldane" (a real person)?
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40304937
^Yup!  Or "John Jacob Jingleheimer Schmidt"
0
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!

 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 500 total points
ID: 40304946
In the case of more than one name:
C1:
=MID(SUBSTITUTE(A1," ","|",LEN(LEFT(A1,FIND(",",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,FIND(",",A1)-1)," ",""))),FIND("|",SUBSTITUTE(A1," ","|",LEN(LEFT(A1,FIND(",",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,FIND(",",A1)-1)," ",""))))+1,FIND(",",SUBSTITUTE(A1," ","|",LEN(LEFT(A1,FIND(",",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,FIND(",",A1)-1)," ",""))))-FIND("|",SUBSTITUTE(A1," ","|",LEN(LEFT(A1,FIND(",",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,FIND(",",A1)-1)," ",""))))-1)

Unfortunately, won't work for suffixes like "Sr." or "Jr." or "MD"

-Glenn
0
 
LVL 4
ID: 40304948
No middle or multiple names I am aware of.  
But Good God if that happens I will kill somebody!...  Good thing I am the Active Directory person.  If it happens it would definitely be my fault. Bad enough the women who get divorced and want new email boxes AND username signons AND display name changes!  
lol,,, Now you guys are going to make me check if someone did do that!  But for now, I think I can figure out that exception to the rule.  So much appreciated.  Function works great!  and the "what if" question.
0
 
LVL 4
ID: 40304950
WOW Glenn you are brilliant.  Especially on the last post.  I will use that for C1 (Just In Case).  How you know that huge function is beyond me, but wow.  You are truly the expert!!!!...   You saved me big time!
0
 
LVL 4

Author Closing Comment

by:get-ADuser -F ($_.Name -eq "Todd")
ID: 40304952
Exceptional Expert!
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40304955
Thanks.  It looks gawdawful, but the trick is to break the function up into smaller parts.  I've attached an example workbook that shows that for future reference.

-Glenn
EE-ExtractName.xlsx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
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…

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