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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
How about this?

Code:
Option Explicit
Sub ConvName()
Dim FullName As String
Dim TName As String
Dim TspcCount As Integer
Dim Cloop As Integer
Dim Tloop As Integer
Dim LastRowNo As Long
Dim FirstName As String
Dim ConvertedName As String


LastRowNo = ActiveSheet.Range("A1048576").End(xlUp).Row


For Tloop = 1 To LastRowNo
    FullName = ActiveSheet.Range("A" & Tloop).Value
    TspcCount = 0
    For Cloop = 1 To Len(FullName)
        If Mid(FullName, Cloop, 1) = Chr$(32) Then TspcCount = TspcCount + 1
    Next Cloop
    TName = FullName
    ConvertedName = ""
    Do While Len(TName) > 0
        If TspcCount > 0 Then
            FirstName = Left(TName, 1)
            ConvertedName = ConvertedName & " " & FirstName
            TName = Right(TName, Len(TName) - InStr(1, TName, " "))
            TspcCount = TspcCount - 1
        Else
            ConvertedName = ConvertedName & " " & TName
            TName = ""
        End If
    Loop
    ActiveSheet.Range("D" & Tloop).Value = ConvertedName
Next Tloop
End Sub
 
Upvote 0
Hi,

Depending on the version of excel you are using (this feature might only be on O365 excel or excel 2016) so in column A1 you have names Peter John Thomas (and the rest of the names in that cell).
In cell B1 write P J Thomas then select the column and Flash fill (on the ribbon bar under Home, then on the right hand side click on the dropdown on "Fill" and select flashfill), it will do exactly as you ask for the whole range
 
Upvote 0
If you have Office 365 with the TEXTJOIN function:

ABC
Mary Jane Louise WilsonM J L Wilson
Peter John ThomasP J Thomas
John DoeJ Doe
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

</tbody>
Sheet3

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]B1[/TH]
[TD="align: left"]{=TEXTJOIN(" ",TRUE,IF(MID(" "&A1,ROW(INDIRECT("1:"&LEN(A1))),1)<>" ","",MID(A1,ROW(INDIRECT("1:"&LEN(A1))),IF(ISERROR(FIND(" ",A1,ROW(INDIRECT("1:"&LEN(A1))))),99,1))))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



Note that it could still fail with some 2 part last names, such as the last example.
 
Last edited:
Upvote 0
Thanks guys,
Probably my original post is not clear, the names are individually in a cell i.e. the first person is in A1, second in A2 etc. I am using Office Professional 2013.

So A1 has Peter John Thomas, A2 has Mary Jane Louise Wilson, A3 George Smith etc.

Eric W, I tried your suggestion but getting #NAME ? as the result.
 
Upvote 0
You're getting the #NAME error because Excel 2013 does not have TEXTJOIN. Since you don't want VBA, the next best option is Flash Fill as suggested in post #4 . Given the layout I showed in post #6 , you'd put "M J L Wilson" in B1 (no quotes), then keep the B1 cell selected, then press Control+E.

The only other option I can think of at the moment is a long, complicated formula that would work for a maximum of 3 initials. I don't have the time to figure it out right now, but perhaps tomorrow.
 
Upvote 0
Hi,

excel_learnerz's suggestion in Post # 4 and 5 should do what you asked, try it.
 
Upvote 0
Apologies, the solution I want is not for a one off conversion but in a template where a new workbook is created for each client where clients names (Mum, Dad, children etc.) are completed in full in a cells (say B20 to B25) and in other sheets in that workbook I need their names as initials and surname. I know I could just type their names into say 4 separate cells (three for first names and one for surname) but for various reasons it is easier to type the name in full in the one cell.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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