PC Review


Reply
Thread Tools Rate Thread

Extract first names, middle names, last names and JR/SR

 
 
MrsMrfy
Guest
Posts: n/a
 
      5th Mar 2008
I have formulas which will extract first, middle and last names but I
need one that will append the JR/SR/III onto the middle name. What I
have now assumes it is the last name.

Thanks for your help.
 
Reply With Quote
 
 
 
 
Niek Otten
Guest
Posts: n/a
 
      5th Mar 2008
Post formulas and examples of your data and required results

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


"MrsMrfy" <(E-Mail Removed)> wrote in message news:38204126-a99c-470d-a312-(E-Mail Removed)...
|I have formulas which will extract first, middle and last names but I
| need one that will append the JR/SR/III onto the middle name. What I
| have now assumes it is the last name.
|
| Thanks for your help.


 
Reply With Quote
 
 
 
 
Ron Rosenfeld
Guest
Posts: n/a
 
      5th Mar 2008
On Wed, 5 Mar 2008 12:45:07 -0800 (PST), MrsMrfy <(E-Mail Removed)> wrote:

>I have formulas which will extract first, middle and last names but I
>need one that will append the JR/SR/III onto the middle name. What I
>have now assumes it is the last name.
>
>Thanks for your help.


Examples of your data, and desired results, would be helpful.
--ron
 
Reply With Quote
 
MrsMrfy
Guest
Posts: n/a
 
      5th Mar 2008
On Mar 5, 2:59*pm, "Niek Otten" <nicol...@xs4all.nl> wrote:
> Post formulas and examples of your data and required results
>
> --
> Kind regards,
>
> Niek Otten
> Microsoft MVP - Excel
>
> "MrsMrfy" <MrsM...@gmail.com> wrote in messagenews:38204126-a99c-470d-a312-(E-Mail Removed)...
>
> |I have formulas which will extract first, middle and last names but I
> | need one that will append the JR/SR/III onto the middle name. *What I
> | have now assumes it is the last name.
> |
> | Thanks for your help.


My data looks like this: (single cell): James P. Smith Jr and I want
it to be Smith, James P Jr. Thanks.

These are my formulas:

=LEFT(A40,FIND(" ",A40)-1)

=RIGHT(A40,LEN(A40)-FIND("*",substitute(A40," ","*",LEN(A40)-
LEN(SUBSTITUTE(A40," ","")))))

=IF(ISERR(MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
",A40)-1)),"",MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
",A40)-1))

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      6th Mar 2008
On Wed, 5 Mar 2008 14:18:30 -0800 (PST), MrsMrfy <(E-Mail Removed)> wrote:

>My data looks like this: (single cell): James P. Smith Jr and I want
>it to be Smith, James P Jr. Thanks.
>
>These are my formulas:
>
>=LEFT(A40,FIND(" ",A40)-1)
>
>=RIGHT(A40,LEN(A40)-FIND("*",substitute(A40," ","*",LEN(A40)-
>LEN(SUBSTITUTE(A40," ","")))))
>
>=IF(ISERR(MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
>",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
>",A40)-1)),"",MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
>",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
>",A40)-1))


If all of your data looks exactly like your example (e.g. FirstName
MiddleInitial LastName Suffix, then you can use this formula (with the name in
A1):

=MID(A1,1+FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2)),-1+
FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),3))-FIND(CHAR(1),
SUBSTITUTE(A1," ",CHAR(1),2)))&", "&LEFT(A1,FIND(" ",A1))&
MID(A1,FIND(" ",A1),FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2))-
FIND(" ",A1)+1)& MID(A1,FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),3))+1,255)

But there are a variety of ways that names can be entered. And if you have
names entered with formats other than the way you describe it above, things can
get very complicated. For example,

do all of your names have suffixes?

Do they all have middle initials or names?

Do any have multiple middle initials or names?

If there is a middle name entered, do you want that returned or just the MI?

Is there no punctuation other than a "." following a middle initial?

Any hyphenated last names?

Any with prefixes?

etc.

Rearranging the names can be done, but if the patterns are any more complicated
than the one you show, you will need to define them for us.
--ron
 
Reply With Quote
 
MrsMrfy
Guest
Posts: n/a
 
      6th Mar 2008
On Mar 5, 8:39*pm, Ron Rosenfeld <ronrosenf...@nospam.org> wrote:
> On Wed, 5 Mar 2008 14:18:30 -0800 (PST), MrsMrfy <MrsM...@gmail.com> wrote:
> >My data looks like this: (single cell): *James P. Smith Jr *and I want
> >it to be Smith, James P Jr. *Thanks.

>
> >These are my formulas:

>
> >=LEFT(A40,FIND(" ",A40)-1)

>
> >=RIGHT(A40,LEN(A40)-FIND("*",substitute(A40," ","*",LEN(A40)-
> >LEN(SUBSTITUTE(A40," ","")))))

>
> >=IF(ISERR(MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
> >",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
> >",A40)-1)),"",MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
> >",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
> >",A40)-1))

>
> If all of your data looks exactly like your example (e.g. FirstName
> MiddleInitial LastName Suffix, then you can use this formula (with the name in
> A1):
>
> =MID(A1,1+FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2)),-1+
> FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),3))-FIND(CHAR(1),
> SUBSTITUTE(A1," ",CHAR(1),2)))&", "&LEFT(A1,FIND(" ",A1))&
> MID(A1,FIND(" ",A1),FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2))-
> FIND(" ",A1)+1)& MID(A1,FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),3))+1,255)
>
> But there are a variety of ways that names can be entered. *And if you have
> names entered with formats other than the way you describe it above, things can
> get very complicated. *For example,
>
> do all of your names have suffixes?
>
> Do they all have middle initials or names?
>
> Do any have multiple middle initials or names?
>
> If there is a middle name entered, do you want that returned or just the MI?
>
> Is there no punctuation other than a "." following a middle initial?
>
> Any hyphenated last names?
>
> Any with prefixes?
>
> etc.
>
> Rearranging the names can be done, but if the patterns are any more complicated
> than the one you show, you will need to define them for us.
> --ron- Hide quoted text -
>
> - Show quoted text -


Sorry, I should have been more specific.
1) No prefixes
2) Some w/first and last name only
3) Some middle names
4) Some beginning initials
5) Some middle initials
6) No punctuation except after initials
7) Some names with JR/SR/III
Thanks.


 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      6th Mar 2008
On Thu, 6 Mar 2008 06:29:30 -0800 (PST), MrsMrfy <(E-Mail Removed)> wrote:

>On Mar 5, 8:39*pm, Ron Rosenfeld <ronrosenf...@nospam.org> wrote:
>> On Wed, 5 Mar 2008 14:18:30 -0800 (PST), MrsMrfy <MrsM...@gmail.com> wrote:
>> >My data looks like this: (single cell): *James P. Smith Jr *and I want
>> >it to be Smith, James P Jr. *Thanks.

>>
>> >These are my formulas:

>>
>> >=LEFT(A40,FIND(" ",A40)-1)

>>
>> >=RIGHT(A40,LEN(A40)-FIND("*",substitute(A40," ","*",LEN(A40)-
>> >LEN(SUBSTITUTE(A40," ","")))))

>>
>> >=IF(ISERR(MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
>> >",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
>> >",A40)-1)),"",MID(A40,FIND(" ",A40)+1,IF(ISERR(FIND(" ",A40,FIND("
>> >",A40)+1)),FIND(" ",A40),FIND(" ",A40,FIND(" ",A40)+1))-FIND("
>> >",A40)-1))

>>
>> If all of your data looks exactly like your example (e.g. FirstName
>> MiddleInitial LastName Suffix, then you can use this formula (with the name in
>> A1):
>>
>> =MID(A1,1+FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2)),-1+
>> FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),3))-FIND(CHAR(1),
>> SUBSTITUTE(A1," ",CHAR(1),2)))&", "&LEFT(A1,FIND(" ",A1))&
>> MID(A1,FIND(" ",A1),FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2))-
>> FIND(" ",A1)+1)& MID(A1,FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),3))+1,255)
>>
>> But there are a variety of ways that names can be entered. *And if you have
>> names entered with formats other than the way you describe it above, things can
>> get very complicated. *For example,
>>
>> do all of your names have suffixes?
>>
>> Do they all have middle initials or names?
>>
>> Do any have multiple middle initials or names?
>>
>> If there is a middle name entered, do you want that returned or just the MI?
>>
>> Is there no punctuation other than a "." following a middle initial?
>>
>> Any hyphenated last names?
>>
>> Any with prefixes?
>>
>> etc.
>>
>> Rearranging the names can be done, but if the patterns are any more complicated
>> than the one you show, you will need to define them for us.
>> --ron- Hide quoted text -
>>
>> - Show quoted text -

>
>Sorry, I should have been more specific.
>1) No prefixes
>2) Some w/first and last name only
>3) Some middle names
>4) Some beginning initials
>5) Some middle initials
>6) No punctuation except after initials
>7) Some names with JR/SR/III
>Thanks.
>


OK, that's more clear. I wrote a UDF that takes the entry in the formats you
have specified, and outputs it they way you described earlier.

Here is what I used for a sample:

James P. Smith Jr
James Smith
James Smith III
James Papa Smith Sr
James Smith Sr

Here are the results of this function:

Smith, James P. Jr
Smith, James
Smith, James III
Smith, James Papa Sr
Smith, James Sr

If there are more variations, or you need different output, let me know.

To set up this function, <alt-F11> opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code below into the window that opens.

To use this, enter the function =ParseName(cell_ref) into any cell, where
cell_ref refers to the location of your unprocessed string.

=========================================
Option Explicit
Function ParseName(str As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "(^\s*\w+)\s*(([\w.]*?)\s*)?(\w+)\s*(JR|SR|III|$)"
ParseName = re.Replace(str, "$4, $1 $3 $5")
ParseName = Application.WorksheetFunction.Trim(ParseName)
End Function
====================================

--ron
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      7th Mar 2008
> OK, that's more clear. I wrote a UDF that takes the entry in the formats
> you
> have specified, and outputs it they way you described earlier.
>
> Here is what I used for a sample:
>
> James P. Smith Jr
> James Smith
> James Smith III
> James Papa Smith Sr
> James Smith Sr
>
> Here are the results of this function:
>
> Smith, James P. Jr
> Smith, James
> Smith, James III
> Smith, James Papa Sr
> Smith, James Sr
>
> If there are more variations, or you need different output, let me know.
>
> To set up this function, <alt-F11> opens the VBEditor. Ensure your
> project is
> highlighted in the Project Explorer window, then Insert/Module and paste
> the
> code below into the window that opens.
>
> To use this, enter the function =ParseName(cell_ref) into any cell, where
> cell_ref refers to the location of your unprocessed string.
>
> =========================================
> Option Explicit
> Function ParseName(str As String) As String
> Dim re As Object
> Set re = CreateObject("vbscript.regexp")
> re.IgnoreCase = True
> re.Global = True
> re.Pattern = "(^\s*\w+)\s*(([\w.]*?)\s*)?(\w+)\s*(JR|SR|III|$)"
> ParseName = re.Replace(str, "$4, $1 $3 $5")
> ParseName = Application.WorksheetFunction.Trim(ParseName)
> End Function
> ====================================


I had a co-worker before I retired whose name was Frank Della Rossa, Della
Rossa was his last name. I'm guessing there is no way to handle a name like
his as there is no outward sign that the Della is not a middle name.

Rick

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      7th Mar 2008
On Thu, 6 Mar 2008 20:52:14 -0500, "Rick Rothstein \(MVP - VB\)"
<(E-Mail Removed)> wrote:

>I had a co-worker before I retired whose name was Frank Della Rossa, Della
>Rossa was his last name. I'm guessing there is no way to handle a name like
>his as there is no outward sign that the Della is not a middle name.
>
>Rick


I'm no expert in this area, but I think the only way to handle that sort of
issue is with a lookup table. And even then, I suppose there could be a Frank
Rossa around who just happened to have Della as his middle name!

My wife has five names plus a preposition. But the first is still the first
name, and the last -- the last name.

--ron
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: creating last name first, first name last from a column of first name last name data Lars-Åke Aspelin Microsoft Excel Programming 0 27th Jul 2009 07:32 AM
Re: creating last name first, first name last from a column of first name last name data Rick Rothstein Microsoft Excel Programming 0 27th Jul 2009 07:25 AM
Re: last name first, first name last -- is there a code to combine 2 cells with last and first names? Patrick Molloy Microsoft Excel Programming 1 17th Jul 2009 12:40 PM
RE: Chg 1 "Last, First Mid" column to 3 "First", "Middle", "Last" pgarcia Microsoft Excel Misc 0 15th Aug 2008 06:31 PM
Expression to middle name/initial from "Last, First Middle" =?Utf-8?B?VGlt?= Microsoft Access Queries 1 24th Jun 2005 06:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 AM.