Get Last names from on multiple full names

nikhil0311

Board Regular
Joined
May 3, 2013
Messages
200
Office Version
  1. 2013
Platform
  1. Windows
Hello Friends, looking for some advanced excel formula help. I want to get the last name only based on multiple full names. There can be any number of full names in a single cell and for those i want the last names in column B (per below example). Please let me know if any excel formula can achieve this output.


last name based on multiple full names.xlsx
ABC
1Sr noFull nameOutput - Last name
21Arteta, Mikel; Trossard, Leandro N; Nelson, Robin TArteta, Trossard, Nelson
32Ramsey, Aaron N; Hazard, Eden MRamsey, Hazard
43Wenger, A WWenger
Sheet1
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If you are still using Excel 2013 as shown in your profile, doing this with worksheet formulas would not be easy.
Instead, you could consider the user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.

VBA Code:
Function LastNames(s As String) As String
  Dim itm As Variant
  
  For Each itm In Split(s, ";")
    LastNames = LastNames & ", " & Trim(Split(itm, ",")(0))
  Next itm
  LastNames = Mid(LastNames, 3)
End Function

nikhil0311.xlsm
BC
1Full nameOutput - Last name
2Arteta, Mikel; Trossard, Leandro N; Nelson, Robin TArteta, Trossard, Nelson
3Ramsey, Aaron N; Hazard, Eden MRamsey, Hazard
4Wenger, A WWenger
5Hall-Oates, TomHall-Oates
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=LastNames(B2)
 
Upvote 0
If you are still using Excel 2013 as shown in your profile, doing this with worksheet formulas would not be easy.
Instead, you could consider the user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.

VBA Code:
Function LastNames(s As String) As String
  Dim itm As Variant
 
  For Each itm In Split(s, ";")
    LastNames = LastNames & ", " & Trim(Split(itm, ",")(0))
  Next itm
  LastNames = Mid(LastNames, 3)
End Function

nikhil0311.xlsm
BC
1Full nameOutput - Last name
2Arteta, Mikel; Trossard, Leandro N; Nelson, Robin TArteta, Trossard, Nelson
3Ramsey, Aaron N; Hazard, Eden MRamsey, Hazard
4Wenger, A WWenger
5Hall-Oates, TomHall-Oates
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=LastNames(B2)
This is great Mr. Peter. Thanks a lot for a quick turn around. One minor change, how do i replace "," with ";" in the final output?
 
Upvote 0
One minor change, how do i replace "," with ";" in the final output?
Rich (BB code):
Function LastNames(s As String) As String
  Dim itm As Variant
 
  For Each itm In Split(s, ";")
    LastNames = LastNames & "; " & Trim(Split(itm, ",")(0))
  Next itm
  LastNames = Mid(LastNames, 3)
End Function
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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