Hello - My worksheet has a range of names (not similar), where some have
first, mid and last names, some have first and last names, first, last and
suffix etc. I came across a tutorial that helped me separate first, mid and
last name, but the forumula doesn't work if there is no middle name.. I want
to create a macro so I don't have to manually do a text-to-column every time.
Sample data:
Eric M Barnes
Edward L Bassard III
Aurora Sofia Garcia
Angela N Higginbotham
Amanda Marie Roccuzzo
Brent Murakami
Forumla tried -
Left: =LEFT(A3, SEARCH(" ",A3,1)) --- works good
Mid: =MID(A2,SEARCH(" ",A2,1)+1,SEARCH(" ",A2,SEARCH(" ",A2,1)+1)-SEARCH("
",A2,1)) ------- works only if there is a middle initial, else returns a
#VALUE.
Right =RIGHT(A2,LEN(A2)-SEARCH(" ",A2,SEARCH(" ",A2,1)+1)) ---- doesn't work
if I use the Left and Mid formula, but there is NO middle name/initial.
Please assist ASAP.
Thanks!
|
|
0
|
|
|
|
Reply
|
Utf
|
12/17/2009 11:52:02 PM |
|
For mid try
=IF(ISERROR(SEARCH(" ",A2,SEARCH(" ",A2,1)+1)),"",MID(A2,SEARCH("
",A2,1)+1,SEARCH(" ",A2,SEARCH(" ",A2,1)+1)-SEARCH(" ",A2,1)))
for right try
=IF(ISERROR(SEARCH(" ",A2,SEARCH(" ",A2,1)+1)),RIGHT(A2,LEN(A2)-SEARCH("
",A2,1)),RIGHT(A2,LEN(A2)-SEARCH(" ",A2,SEARCH(" ",A2,1)+1)))
--
If this is the answer you hoped for please remember to click the yes button
below...
Kind regards
Rik
"NoviceUser" wrote:
> Hello - My worksheet has a range of names (not similar), where some have
> first, mid and last names, some have first and last names, first, last and
> suffix etc. I came across a tutorial that helped me separate first, mid and
> last name, but the forumula doesn't work if there is no middle name.. I want
> to create a macro so I don't have to manually do a text-to-column every time.
>
> Sample data:
>
> Eric M Barnes
> Edward L Bassard III
> Aurora Sofia Garcia
> Angela N Higginbotham
> Amanda Marie Roccuzzo
> Brent Murakami
>
>
> Forumla tried -
> Left: =LEFT(A3, SEARCH(" ",A3,1)) --- works good
>
> Mid: =MID(A2,SEARCH(" ",A2,1)+1,SEARCH(" ",A2,SEARCH(" ",A2,1)+1)-SEARCH("
> ",A2,1)) ------- works only if there is a middle initial, else returns a
> #VALUE.
>
> Right =RIGHT(A2,LEN(A2)-SEARCH(" ",A2,SEARCH(" ",A2,1)+1)) ---- doesn't work
> if I use the Left and Mid formula, but there is NO middle name/initial.
>
> Please assist ASAP.
>
> Thanks!
>
>
|
|
1
|
|
|
|
Reply
|
Utf
|
12/18/2009 12:36:02 AM
|
|
On Thu, 17 Dec 2009 15:52:02 -0800, NoviceUser
<NoviceUser@discussions.microsoft.com> wrote:
>Hello - My worksheet has a range of names (not similar), where some have
>first, mid and last names, some have first and last names, first, last and
>suffix etc. I came across a tutorial that helped me separate first, mid and
>last name, but the forumula doesn't work if there is no middle name.. I want
>to create a macro so I don't have to manually do a text-to-column every time.
>
>Sample data:
>
>Eric M Barnes
>Edward L Bassard III
>Aurora Sofia Garcia
>Angela N Higginbotham
>Amanda Marie Roccuzzo
>Brent Murakami
>
>
>Forumla tried -
>Left: =LEFT(A3, SEARCH(" ",A3,1)) --- works good
>
>Mid: =MID(A2,SEARCH(" ",A2,1)+1,SEARCH(" ",A2,SEARCH(" ",A2,1)+1)-SEARCH("
>",A2,1)) ------- works only if there is a middle initial, else returns a
>#VALUE.
>
>Right =RIGHT(A2,LEN(A2)-SEARCH(" ",A2,SEARCH(" ",A2,1)+1)) ---- doesn't work
>if I use the Left and Mid formula, but there is NO middle name/initial.
>
>Please assist ASAP.
>
>Thanks!
>
This macro will parse the cells that you select into the three adjacent
columns.
The First Name is the first space-delimited word in the string.
The Last Name is the last word in the string, UNLESS it is followed by one of
the suffixes that are in the pipe-delimited list of sPat, in which case it
would be the next-to-last word.
The Middle Name is anything in between the first and last names.
As written, the names must consist of letters and/or hyphens.
To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this Macro (Sub), first Select the range to parse. Then <alt-F8> opens
the macro dialog box. Select the macro by name, and <RUN>.
=============================================
Option Explicit
Sub ParseName()
Dim c As Range, rg As Range
Dim s As String
Dim re As Object, mc As Object
Const sPat As String = _
"^(\b[A-Z-]+\b)\s*([\sA-Z-.]+)?\s+(\b[A-Z-]" _
& "+\b)\s*(Jr|Sr|III|II|IV|MD|M\.D\.|PhD\.?)?\s*$"
Set re = CreateObject("vbscript.regexp")
re.Pattern = sPat
re.ignorecase = True
Set rg = Selection 'although could set rg differently
Range(rg.Offset(0, 1), rg.Offset(0, 3)).ClearContents
For Each c In rg
s = c.Value
If re.test(s) = True Then
Set mc = re.Execute(s)
c.Offset(0, 1).Value = mc(0).submatches(0)
c.Offset(0, 2).Value = mc(0).submatches(1)
c.Offset(0, 3).Value = mc(0).submatches(2)
End If
Next c
End Sub
====================================
--ron
|
|
0
|
|
|
|
Reply
|
Ron
|
12/18/2009 2:00:44 AM
|
|
|
2 Replies
1405 Views
(page loaded in 4.157 seconds)
Similiar Articles: Separate first name, middle name and last name - microsoft.public ...Hello - My worksheet has a range of names (not similar), where some have first, mid and last names, some have first and last names, first, last and ... Spliting First Middle and Last Name - microsoft.public.access ...We have fields that are LastName/FirstName Middle and sometimes a number, ex. Smith/Linda S 3. Any suggestions how to split up and not include ... Separate Names - microsoft.public.access... Doe, MD, PhD Tom L. Smith, Jr., DO Nancy Jones, MD I want to separate the names into individual fields. For Example: FIRST NAME MIDDLE NAME LAST ... Switch Last Name First Name to First Name Last Name - microsoft ...Separate first name, middle name and last name - microsoft.public ..... some ... Microsoft Newsgroups Switch Last Name First Name to First ... Some names have Middle Names ... convert from last name, first name TO first name, last name ...Separate first name, middle name and last name - microsoft.public ... ... I will be adding names and ... Excel Convert last name comma first name into two separate cells ... Switch First and Last Names - microsoft.public.excel.worksheet ...Separate Names - microsoft.public.access Separate first name, middle name and last name - microsoft.public ... Switch Last Name First Name to First Name Last Name ... Parsing Names - microsoft.public.access.queriesTypically this involves parsing names into parts, such as title, first name, middle name, last ... ... How do I separate first and last names into two columns ... titling ... Extracting First Name from cell with first name and last name ...Separate first name, middle name and last name - microsoft.public ... ... Mid formula, but there is NO middle name/initial. ... Extracting First Names, Middle Names, and Last ... Need to separate and rearrange names - microsoft.public.excel ...Need to separate and rearrange names - microsoft.public.excel ... Separate first name, middle name and last name - microsoft ... middle and last names stored in separate ... Extract First Name From String - microsoft.public.sqlserver ...Separate first name, middle name and last name - microsoft.public ... Spliting First Middle and Last Name - microsoft.public.access ... If the last and first names are always ... How to separate the first name, middle name and last name? - YouTubePROBLEM 1: How to remove dot and dash in the middle of number? PROBLEM 2: How to separate the first name, middle name and last name? Problem solving 1 ... How to split name in to first name, last name and middle initial ...I have a list of provider names. Which include professional and facility names in the same column. My objective here is to split the professional ... Excel - Separate Middle Initial From First Name - Hi All I have ...Separate Middle Initial From First Name - Hi All I have a list of names stored in MS Excel Last... - Free Excel Help Separate first name, middle name and last name - microsoft.public ...Hello - My worksheet has a range of names (not similar), where some have first, mid and last names, some have first and last names, first, last and ... Full Name to First | Middle | LastI have about 5,000 Full Names in one column. I would like to separate these into ... Try using Text to column method. Select the column with the names (make sure the ... 7/22/2012 4:48:32 PM
|