Convert this Name-Separating Macro into Formulas?

jeffcoleky

Active Member
Joined
May 24, 2011
Messages
274
The goal is to turn This:
Excel 2010
A
Names Pre-Split
Armstrong Charles A Sr
Brackney Michael & Robin
Capland Yosef & Chava N
Fowler Kenneth
Kimbrough Vanessa G
Thammachart Suwanit & Gagel Tabitha

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

</tbody>
Sheet1
Into This:
Excel 2010
BCDE
First Name 1Last Name 1First Name 2Last Name 2
CharlesArmstrong
MichaelBrackneyRobinBrackney
YosefCaplandChavaCapland
KennethFowler
VanessaKimbrough
SuwanitThammachartTabithaGagel

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

</tbody>
Sheet1
Here is the MACRO that does this for me: (Note, the macro also adds columns for middle names/initials which I wish to exclude as well)


Code:
Sub Last_First_Split()

    Dim rng As Range, cell As Range, Names As Variant, NameParts As Variant
    
    Set rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
    
    Application.ScreenUpdating = False
    
    rng.Offset(, 1).Resize(, 6).ClearContents
    
    For Each cell In rng
        If cell.Value <> "" Then
            Names = Split(Application.WorksheetFunction.Trim(cell.Value), " & ")
            
            ' Single name or 1st of Couple
            NameParts = Split(Names(0), " ")
            cell.Offset(, 1).Value = StrConv(NameParts(1), vbProperCase)
            If UBound(NameParts) = 2 Then cell.Offset(, 2).Value = StrConv(NameParts(2), vbProperCase)
            cell.Offset(, 3).Value = StrConv(NameParts(0), vbProperCase)
            
            ' 2nd name if Couple
            If UBound(Names) > 0 Then
                NameParts = Split(Names(1), " ")
                If UBound(NameParts) = 0 Then
                    ' Pat
                    cell.Offset(, 4).Value = StrConv(NameParts(0), vbProperCase)
                    cell.Offset(, 6).Value = cell.Offset(, 3).Value
                ElseIf UBound(NameParts) = 1 And Len(NameParts(1)) = 1 Then
                    ' Pat E
                    cell.Offset(, 4).Value = StrConv(NameParts(0), vbProperCase)
                    cell.Offset(, 5).Value = UCase(NameParts(1))
                    cell.Offset(, 6).Value = cell.Offset(, 3).Value
                Else
                    ' Jones Sarah  or  Jones Sarah A
                    cell.Offset(, 4).Value = StrConv(NameParts(1), vbProperCase)
                    If UBound(NameParts) = 2 Then cell.Offset(, 5).Value = StrConv(NameParts(2), vbProperCase)
                    cell.Offset(, 6).Value = StrConv(NameParts(0), vbProperCase)
                End If
            End If
        End If
    Next cell
    
    Application.ScreenUpdating = True


End Sub

This is a great macro and it has worked great for me but now our needs have changed and I need formulas to be used in columns B, C, D, & E instead of the macro. Can anyone help me convert it?

EXCEL FILE HERE:http://goo.gl/ZY1xI


 
Try this:
[TABLE="width: 157"]
<TBODY>[TR]
[TD]If this is in D9:[TABLE="width: 157"]
<TBODY>[TR]
[TD]Brackney Michael & Robin


Last name formula: =LEFT(D9,FIND(" ",D9)-1)


First First name formula:=MID(D9,FIND(" ",D9)+1,FIND(" ",D9)-1)

2nd First Name Formula: =MID(D9,FIND("&",D9)+1,FIND(" ",D9)-1)[/TD]
[/TR]
</TBODY><COLGROUP><COL></COLGROUP>[/TABLE]

[/TD]
[/TR]
</TBODY><COLGROUP><COL></COLGROUP>[/TABLE]
 
Upvote 0
Try this:
If this is in D9:Brackney Michael & Robin


Last name formula: =LEFT(D9,FIND(" ",D9)-1)


First First name formula:=MID(D9,FIND(" ",D9)+1,FIND(" ",D9)-1)

2nd First Name Formula: =MID(D9,FIND("&",D9)+1,FIND(" ",D9)-1)
 
Upvote 0
Try this:

Thank you but I will need something more complex than that due to the varying names in column A. I can't figure out how to adapt it based upon all the different possibilities.

The format could be one of several ways. I'll use the same name in all ways it might show up:

Excel 2010
AB
Names Pre-SplitVariation
Brackney MichaelNo middle name, one person only
Brackney Michael FrankMiddle name included, one person only
Brackney Michael & RobinNo middle names, same last name
Brackney Michael & Brackney RobinNo middle inames, last name listed twice
Brackney Michael & Jones RobinSame as above, different last names
Brackney Michael & Brackney Robin SaraSame Last Name, middle name/initial for robin listed
Brackney Michael & Jones Robin SaraSame as above, different last names
Brackney Michael F & Brackney Robin SaraSame Last Name, Middle Name/initial for both
Brackney Michael F & Jones Robin SaraSame as above, different last names

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

[TD="align: center"]8[/TD]

[TD="align: center"]9[/TD]

[TD="align: center"]10[/TD]

</tbody>
Sheet1
(Middle name not needed)


The formulas you provided are great for when only the first line is true but what do we do for all the other variations, just like the macro did?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,848
Messages
6,193,319
Members
453,790
Latest member
yassinosnoo1

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