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
1Names Pre-Split
2Armstrong Charles A Sr
3Brackney Michael & Robin
4Capland Yosef & Chava N
5Fowler Kenneth
6Kimbrough Vanessa G
7Thammachart Suwanit & Gagel Tabitha

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

<tbody>
</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


 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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)

<TBODY>
</TBODY><COLGROUP><COL></COLGROUP>


<TBODY>
</TBODY><COLGROUP><COL></COLGROUP>
 
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
1Names Pre-SplitVariation
2Brackney MichaelNo middle name, one person only
3Brackney Michael FrankMiddle name included, one person only
4Brackney Michael & RobinNo middle names, same last name
5Brackney Michael & Brackney RobinNo middle inames, last name listed twice
6Brackney Michael & Jones RobinSame as above, different last names
7Brackney Michael & Brackney Robin SaraSame Last Name, middle name/initial for robin listed
8Brackney Michael & Jones Robin SaraSame as above, different last names
9Brackney Michael F & Brackney Robin SaraSame Last Name, Middle Name/initial for both
10Brackney Michael F & Jones Robin SaraSame as above, different last names

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</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,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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