Parse data into 3 data point (first, middle and last name)

smith44x

New Member
Joined
Oct 30, 2019
Messages
1
I am having difficulty parsing approx. 2000 rows of contact name into three separate columns first name, middle name and last name. The data does not have a consistent separator such as a comma etc.

sample data

[TABLE="width: 258"]
<colgroup><col></colgroup><tbody>[TR]
[TD]wendy»Karola¬WINKETT[/TD]
[/TR]
[TR]
[TD]Vittorio‡halstead[/TD]
[/TR]
[TR]
[TD]MEADE¬chicky¬¬SEPPEY[/TD]
[/TR]
[TR]
[TD]kandace¬Tiler[/TD]
[/TR]
[TR]
[TD]Wyn¬rameaux[/TD]
[/TR]
[TR]
[TD]CRISTY‡‡Birden[/TD]
[/TR]
[TR]
[TD]gifford»‡Reymers[/TD]
[/TR]
[TR]
[TD]janeva»Glenine‡cotherill[/TD]
[/TR]
[TR]
[TD]WEBB‡Stanlock[/TD]
[/TR]
[TR]
[TD]Emlynne‡Henriette»¬matchett[/TD]
[/TR]
[TR]
[TD]YANK‡Zak‡vearncombe[/TD]
[/TR]
[TR]
[TD]mabel‡ulster[/TD]
[/TR]
</tbody>[/TABLE]


Tried working with magic trick 531 to no avail.

Please let me know your thoughts!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
If there are only 2 parts name e.g "Vittorio‡halstead" then column middle name should be blank?
Try this:
Put data in col A then run the code.

Code:
[FONT=Lucida Console][COLOR=Royalblue]Sub[/COLOR] a1113731a()
[I][COLOR=Dimgray]'https://www.mrexcel.com/forum/excel-questions/1113731-parse-data-into-3-data-point-first-middle-last-name.html[/COLOR][/I]
[COLOR=Royalblue]Dim[/COLOR] regEx [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Object[/COLOR], matches [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Object[/COLOR]
[COLOR=Royalblue]Dim[/COLOR] va, vb
[COLOR=Royalblue]Dim[/COLOR] i [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR]

va = Range([COLOR=Darkcyan]"A1"[/COLOR], Cells(Rows.count, [COLOR=Darkcyan]"A"[/COLOR]).[COLOR=Royalblue]End[/COLOR](xlUp))
[COLOR=Royalblue]ReDim[/COLOR] vb([COLOR=Brown]1[/COLOR] [COLOR=Royalblue]To[/COLOR] [COLOR=Royalblue]UBound[/COLOR](va, [COLOR=Brown]1[/COLOR]), [COLOR=Brown]1[/COLOR] [COLOR=Royalblue]To[/COLOR] [COLOR=Brown]3[/COLOR])
       
        [COLOR=Royalblue]Set[/COLOR] regEx = CreateObject([COLOR=Darkcyan]"VBScript.RegExp"[/COLOR])
        [COLOR=Royalblue]With[/COLOR] regEx
            .[COLOR=Royalblue]Global[/COLOR] = True
            .MultiLine = True
            .IgnoreCase = True
            .pattern = [COLOR=Darkcyan]"\w+"[/COLOR]
        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]With[/COLOR]

    [COLOR=Royalblue]For[/COLOR] i = [COLOR=Brown]1[/COLOR] [COLOR=Royalblue]To[/COLOR] [COLOR=Royalblue]UBound[/COLOR](va, [COLOR=Brown]1[/COLOR])
        
        [COLOR=Royalblue]If[/COLOR] regEx.test(va(i, [COLOR=Brown]1[/COLOR])) [COLOR=Royalblue]Then[/COLOR]
            [COLOR=Royalblue]Set[/COLOR] matches = regEx.Execute(va(i, [COLOR=Brown]1[/COLOR]))
            
            vb(i, [COLOR=Brown]1[/COLOR]) = matches([COLOR=Brown]0[/COLOR])
                [COLOR=Royalblue]If[/COLOR] matches.count = [COLOR=Brown]2[/COLOR] [COLOR=Royalblue]Then[/COLOR]
                    vb(i, [COLOR=Brown]3[/COLOR]) = matches([COLOR=Brown]1[/COLOR])
                [COLOR=Royalblue]ElseIf[/COLOR] matches.count = [COLOR=Brown]3[/COLOR] [COLOR=Royalblue]Then[/COLOR]
                    vb(i, [COLOR=Brown]2[/COLOR]) = matches([COLOR=Brown]1[/COLOR])
                    vb(i, [COLOR=Brown]3[/COLOR]) = matches([COLOR=Brown]2[/COLOR])
                [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
    
    [COLOR=Royalblue]Next[/COLOR]

Range([COLOR=Darkcyan]"B1"[/COLOR]).Resize([COLOR=Royalblue]UBound[/COLOR](vb, [COLOR=Brown]1[/COLOR]), [COLOR=Brown]3[/COLOR]) = vb

[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]
 
Upvote 0
I would first replace each of the different seperator characters with a single one such as ~. Then carry out a number of replaces to replace ~~ with ~ (keep doing this till no replaces takes place). Finally, use text to columns to seperate out.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top