Extracting Initials and surname from cell

Hudco

Board Regular
Joined
Jan 4, 2006
Messages
125
Office Version
  1. 365
I have a column which contains first names and surnames in the cells. I want to extract the initials and the full surname from each cell. e.g. cell A1 will have Peter John Thomas which I want to convert to P J Thomas, cell A2 has Mary Jane Louise Wilson which I want to convert to M J L Wilson.

I have found plenty of help to get all initials but none leaving the surname intact but getting the first initial from multiple first names.

Thanks in advance
 
This works for up to 3 initials. Many caveats based on the format of the names, especially with extra or doubled spaces. You may want to use a helper cell with =TRIM(A1) in it.

=CHOOSE(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1,"",LEFT(A1)&" ",LEFT(A1)&" "&MID(A1,FIND(" ",A1)+1,1)&" ",LEFT(A1)&" "&MID(A1,FIND(" ",A1)+1,1)&" "&MID(A1,FIND(" ",A1,FIND(" ",A1)+1)+1,1)&" ")&TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1)))
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This works with up to 5 elements per name.

=TRIM(LEFT(A1)&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255)),1,1,"")


Excel 2010
AB
1Mary Jane Louise WilsonM J L Wilson
2Peter John ThomasP J Thomas
3Mary Ellen BernardM E Bernard
4Robert Louis StevensonR L Stevenson
5CherCher
6Alan Alexander MilneA A Milne
7William Edward Burghardt DuBoisW E B DuBois
8William Edward Burghardt Du BoisW E B D Bois
Sheet1
Cell Formulas
RangeFormula
B1=TRIM(LEFT(A1)&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255)),1,1,"")
B2=TRIM(LEFT(A2)&" "&LEFT(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",255)),255)),1,1,"")
B3=TRIM(LEFT(A3)&" "&LEFT(TRIM(MID(SUBSTITUTE(A3," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A3," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A3," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A3," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A3," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A3," ",REPT(" ",255)),255)),1,1,"")
B4=TRIM(LEFT(A4)&" "&LEFT(TRIM(MID(SUBSTITUTE(A4," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A4," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A4," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A4," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A4," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A4," ",REPT(" ",255)),255)),1,1,"")
B5=TRIM(LEFT(A5)&" "&LEFT(TRIM(MID(SUBSTITUTE(A5," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A5," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A5," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A5," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A5," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A5," ",REPT(" ",255)),255)),1,1,"")
B6=TRIM(LEFT(A6)&" "&LEFT(TRIM(MID(SUBSTITUTE(A6," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A6," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A6," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A6," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A6," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A6," ",REPT(" ",255)),255)),1,1,"")
B7=TRIM(LEFT(A7)&" "&LEFT(TRIM(MID(SUBSTITUTE(A7," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A7," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A7," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A7," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A7," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A7," ",REPT(" ",255)),255)),1,1,"")
B8=TRIM(LEFT(A8)&" "&LEFT(TRIM(MID(SUBSTITUTE(A8," ",REPT(" ",255)),255,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A8," ",REPT(" ",255)),510,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A8," ",REPT(" ",255)),765,255)))&" "&LEFT(TRIM(MID(SUBSTITUTE(A8," ",REPT(" ",255)),1020,255)))&LEFT(TRIM(MID(SUBSTITUTE(A8," ",REPT(" ",255)),1275,255))))&REPLACE(TRIM(RIGHT(SUBSTITUTE(A8," ",REPT(" ",255)),255)),1,1,"")
 
Upvote 0
Okay, any advances on 5?
Thank you so much Eric and Scott.
Both worked except Scott yours left 2 spaces at the beginning which I will sit down and work out why.
To both of you and families, all the best for the Christmas and New Year.

Addendum - sorted Scott - my cell had indent on, not sure why but fixed.
 
Last edited:
Upvote 0
Glad we could help.

Just how many initials do you expect? Either of our formulas could be modified to allow more initials, they would need more terms added, so they'd get longer.

And Merry Christmas, and Happy Holidays to you too! :biggrin:
 
Last edited:
Upvote 0
Hi,

I was working on a solution for your problem and came up with a Very similar formula to what Scott did in Post # 12, but he had already posted his, so I didn't post mine.

But I couldn't resist trying to come up with a "shorter" formula that can achieve the same results, so I kept trying and this is what I came up with (good for up to 5 name elements):


Book1
AB
1Mary Jane Louise WilsonM J L Wilson
2Peter John ThomasP J Thomas
3John DoeJ Doe
4Mary Ellen BernardM E Bernard
5Robert Louis StevensonR L Stevenson
6CherCher
7Alan Alexander MilneA A Milne
8William Edward Burghardt DuBoisW E B DuBois
9William Edward Burghardt Du BoisW E B D Bois
Sheet395
Cell Formulas
RangeFormula
B1=LEFT(A1)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1)),2)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1,2)),2)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1,3)),2)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1,4)),2)&REPLACE(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)),1,1,"")


Formula copied down.
 
Upvote 0
Thanks jtakw,

Shorter the better. Mind you our longest name is 3 first names but the best thing is all solutions account for a hyphenated name correctly which I couldn't find elsewhere (non-MrExcel) so still the foremost authority thanks to you guys and others.

So thanks again everyone, and seasons greetings.

Clyde
 
Upvote 0
Thanks jtakw,

Shorter the better...the best thing is all solutions account for a hyphenated name correctly which I couldn't find elsewhere (non-MrExcel) so still the foremost authority thanks to you guys and others.

So thanks again everyone, and seasons greetings.

Clyde

Glad you like it shorter, because I realize my formula can be shortened further, the first SUBSTITUTE is not needed, still accommodates up to 5 name elements:


Book1
AB
1Mary Jane Louise WilsonM J L Wilson
2Peter John ThomasP J Thomas
3John DoeJ Doe
4Mary Ellen BernardM E Bernard
5Robert Louis StevensonR L Stevenson
6CherCher
7Alan Alexander MilneA A Milne
8William Edward Burghardt DuBoisW E B DuBois
9William Edward Burghardt Du BoisW E B D Bois
10Mary Ellen Bernard-StevensonM E Bernard-Stevenson
Sheet395
Cell Formulas
RangeFormula
B1=LEFT(A1)&MID(A1,FIND(" ",A1&" "),2)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1,2)),2)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1,3)),2)&MID(A1,FIND(1,SUBSTITUTE(A1&1," ",1,4)),2)&REPLACE(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)),1,1,"")
 
Upvote 0
you can try PowerQuery
doesn't matter how many FNames will be there

FullInitials
Mary Jane Louise WilsonM J L Wilson
Peter John ThomasP J Thomas
Mary Ellen BernardM E Bernard
Robert Louis StevensonR L Stevenson
CherCher
Alan Alexander MilneA A Milne
William Edward Burghardt DuBoisW E B DuBois
William Edward Burghardt Du BoisW E B D Bois
John Jack Jim Jerycho Jack Jacob Joshua Jules BrownJ J J J J J J J Brown
Osama BinladenO Binladen
John Fitzgerald KennedyJ F Kennedy
Martin Luther KingM L King
DummyDummy
Mary Ellen Bernard-StevensonM E Bernard-Stevenson
Carla PughC Pugh
Erica ElliottE Elliott
Xaviera MasonX Mason
Maryam NicholsM Nichols
Hollee BradshawH Bradshaw
Jael GoodJ Good
Shaine SellersS Sellers
Violet McclureV Mcclure
Jacqueline HutchinsonJ Hutchinson
Holly HaleH Hale
Susan OdonnellS Odonnell
Zoe HoodZ Hood
Stephanie RichardsS Richards
Eve KellerE Keller
Emerald GarrettE Garrett
Erin Jane Mary Holcomb-DustinE J M Holcomb-Dustin
Vanna CastanedaV Castaneda
Nichole PatrickN Patrick
Barbara Russell-CliffB Russell-Cliff
Ria CottonR Cotton

Code:
[SIZE=1]let
    C2R = List.Transform({97..122}, each Character.FromNumber(_)),
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Prefix" = Table.TransformColumns(Source, {{"Full", each "x " & _, type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Prefix", "Full", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"Full.1", "Full.2"}),
    #"Added Custom" = Table.AddColumn(#"Split Column by Delimiter", "Custom", each Text.Remove([Full.1], C2R)),
    #"Trimmed Text" = Table.TransformColumns(#"Added Custom",{{"Custom", Text.Trim, type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Trimmed Text",{"Custom", "Full.2"}),
    #"Merged Columns" = Table.CombineColumns(#"Removed Other Columns",{"Custom", "Full.2"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Initials"),
    #"Trimmed Text1" = Table.TransformColumns(#"Merged Columns",{{"Initials", Text.Trim, type text}})

in
    #"Trimmed Text1"[/SIZE]
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,915
Members
449,132
Latest member
Rosie14

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