LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Splitting data into multiple fields.

On Thu, 17 Apr 2008 14:05:00 -0700, DamselNTX
wrote:

I need to split a name field in a column that contains one or all of the
following components without consistency: courtesy title (i.e. Mr.), First
Name, Middle Inital and Last Name. Some examples of records in my column a
Mr. K. Kyle Mathis
Ms. Terri Mathis
Ms. Ellen E. Vallatini
Cole Vallatini
Nick A. Vallatini

I tried using the command "Data" "Text to Columns" but, with the
inconsitency in data, it split correctly in some place but incorrectly in
others. Any ideas?


Parsing names can be tough.

Especially when you don't indicate how you want the names you give parsed!

For Courtesy title, you need to list them all. And even then there may be
errors. For example, in the name M. James Cook, is the M. a courtesy title, or
is it the initial of the first name?

You state the components include FirstName, Middle Initial ...

What is the Middle Initial in your first example?

Mr. K. Kyle Mathis

Or maybe you mean something else?

If you want the name parsed into the fields you listed, should the above look
like:

Mr. | K. | K | Mathis

or do you want the middle name and not just the middle initial?

What if there are multiple middle name/initials?

What about certain foreign names?

In any event, this UDF should give you a start. It assumes that the title is
in pipe separated list you will see in the UDF. It also assumes that the first
word following is the first name; the last word is the last name; and
everything in-between is what you want for the Middle name.

If that is not what you want, you'll have to give more specifics.

You may find problems with certain names, but if you do, you'll have to give
more specifics.

Let me know.

To enter the UDF, <alt-F11 opens the VB Editor. 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 it, enter a formula of the form =ParseName(cell_ref, Component) where
cell_ref refers to a single cell containing the full name; and Component is the
part of that name you want to extract (see the comments within the code for the
translation -- e.g 1 = title; 2=First Name; etc).

=======================================
Option Explicit

Function ParseName(Str As String, Component As Long) As String
'Component Key:
' 1 = Courtesy Title
' 2 = First Name
' 3 = Middle initial or Names
' 4 = Last Name
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "^((Mr|Mrs|Ms|Dr)\.)?\s*(\S+)\s*(.*)?\s+(\S+)$ "
If re.test(Str) = True Then
Set mc = re.Execute(Str)
With mc(0)
Select Case Component
Case Is = 1
ParseName = .submatches(0)
Case Is = 2
ParseName = .submatches(2)
Case Is = 3
ParseName = .submatches(3)
Case Is = 4
ParseName = .submatches(4)
End Select
End With
End If
End Function
=====================================
--ron
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding multiple data fields from time based data. JMK Excel Discussion (Misc queries) 1 July 27th 07 10:59 PM
Splitting Column Data into 2 fields Kevin Excel Worksheet Functions 4 January 28th 06 07:03 AM
splitting fields Randy Patterson Excel Discussion (Misc queries) 2 August 10th 05 01:42 AM
splitting 1 column of data into multiple columns CiceroCF Setting up and Configuration of Excel 1 March 25th 05 01:50 AM
Pivot Tables multiple data fields Excel GuRu Excel Worksheet Functions 2 December 16th 04 12:06 AM


All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"