Excel split cells with full name into 2 columns.

Golaidron

Board Regular
Joined
Jan 23, 2013
Messages
83
Office Version
  1. 365
Platform
  1. Windows
Hi All

Need help her to find some formulas til split up a cell and into 2 cells.
Got thousands of row to edit.

Data i got in column A is set up randomly,

Lastname, Firstname
Lastname, Firstname Middelname
Lastname, Firstname Middelname Middelname

Firstname Lastname
Firstname Middelname Lastname
Firstname Middelname Middelname Lastname

Preferred outcome is
Column B to contain First+middelname
Column C to contain only lastname

Please help.
 
Hi Golaidron,

EXTRACTELEMENT and COUNTSPACES are UDFs - made in the module of the workbook you want to use them in.

You'll need to open up the VBA and paste the function codes in to setup the functions ready to use.

Hold Alt and press F11 to open up VBA, then go to Insert -> Module
Paste the code into the editor and close the VBA (Alt+F11)
Now try the formula again and it should work.

Paste this:
Code:
Function EXTRACTELEMENT(txt, n, sep)
    EXTRACTELEMENT = Split(Application.Trim(txt), sep)(n - 1)
End Function


Function COUNTSPACES(txt As String) As String
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\S"
        COUNTSPACES = Len(.Replace(txt, ""))
    End With
End Function
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi,

No need to install UDFs, these formulas should work:


Book1
ABC
1Jamesson, Adam Mark TerryAdam Mark TerryJamesson
2Peter Richard ClarkPeter RichardClark
3Thatcher, Liz AmyLiz AmyThatcher
Sheet615
Cell Formulas
RangeFormula
B1=TRIM(SUBSTITUTE(A1,IFERROR(LEFT(A1,FIND(",",A1)),TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))),""))
C1=TRIM(SUBSTITUTE(SUBSTITUTE(A1,B1,""),",",""))


Formulas copied down.
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,005
Members
449,279
Latest member
Faraz5023

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