+ Reply to Thread
Results 1 to 9 of 9

Extracting Middle Initial (if present)

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2021
    Location
    Boise, ID
    MS-Off Ver
    Office 2016
    Posts
    7

    Extracting Middle Initial (if present)

    Hi there. First time poster!
    Found this forum while searching google for help.

    I have a list of names first, last and sometimes middle initial. I need to separate them into 3 columns. Getting last name was easy, seperating on the comma. However I need to get Middle Initials out, where present. The problem is that some of the names on the list have 2 names like "Mary Beth", so I cant just split again on space. My sheet has 16k rows, so manually splitting is out of the question. Does anyone have an easy fix for this?
    I was looking for a way to say, like, split after space if following data is 1 or 2 characters (some have periods on initial and some dont)?

    For example, I need it to work with each of those:
    ABBO, KATHERINE M (returns middle Initial M)
    ABBOTT, DANIELLE (returns blank column)
    ABE, HODAKA PAUL (returns blank column)
    ABELLO, RICHARD R. (returns R.)
    ABOU-HARB, JAMIL (blank)
    ABRAHAM, JENNIFER VOSS (Blank)
    Sorry I am an excel noob. Would greatly appreciate any help.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Extracting Middle Initial (if present)

    Formula for B2 to D6 = =TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",100)),1+(COLUMN()-2)*100,100))
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-03-2021
    Location
    Boise, ID
    MS-Off Ver
    Office 2016
    Posts
    7

    Re: Extracting Middle Initial (if present)

    mehmetcik - I am sorry I am so inexperienced, but I cant get this to work. I tried pasting it in formula bar, then tried everything from just the second = onward and selecting columns B though D and it just says "false" in the first column. Got any more clues?

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Extracting Middle Initial (if present)

    Hi there,

    Take a look at the attached workbook and see if it does what you need. It uses the following code:

    
    
    
    Option Explicit
    
    
    Private Sub ProcessNames()
    
        Const sSEPARATOR    As String = " "
    
        Dim iNoOfColumns    As Integer
        Dim sThirdName      As String
        Dim rNewCell        As Range
        Dim vaNames         As Variant
        Dim rCell           As Range
    
        For Each rCell In Selection.Cells
    
    '       Add a separator character at the end of the string
    '       to ensure that the Split method works correctly
            rCell.Value = rCell.Value & sSEPARATOR
    
            vaNames = Split(rCell.Value, sSEPARATOR)
            iNoOfColumns = UBound(vaNames)
    
    '       Insert the Name "components" into the adjacent cells
            With rCell.Offset(0, 1)
    
                Range(.Cells(1, 1), _
                      .Cells(1, iNoOfColumns)).Value = vaNames
    
            End With
    
    '       Remove the comma character at the end of the surname
            Set rNewCell = rCell.Offset(0, 1)
            rNewCell.Value = Replace(rNewCell.Value, ",", vbNullString)
    
            Set rNewCell = rCell.Offset(0, 3)
            sThirdName = rNewCell.Value
    
    '       Proceed only if the third "component" (initial) of the Name is non-blank
            If Len(sThirdName) > 0 Then
    
    '           Allow a single initial followed by a full stop . . .
                If Len(sThirdName) = 2 And _
                   Right$(sThirdName, 1) = "." Then
    
                        rNewCell.Value = sThirdName
    
    '           . . . or else allow a single initial
                ElseIf Len(sThirdName) = 1 Then
    
                        rNewCell.Value = sThirdName
    
    '           . . . but discard any third "component" which is not a single initial
                Else:   rNewCell.Value = vbNullString
    
                End If
    
            End If
    
        Next rCell
    
    End Sub

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-03-2021
    Location
    Boise, ID
    MS-Off Ver
    Office 2016
    Posts
    7

    Re: Extracting Middle Initial (if present)

    Greg, This did work, except for the people with two "first names". It didnt include their second first name in the first name column. Thanks for the attempt!
    Last edited by Eam0n; 12-03-2021 at 05:56 PM.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Extracting Middle Initial (if present)

    Hi again,


    It didnt include their second first name in the first name column

    Hey! That bit wasn't included in the original tech spec.!


    My previous workbook has been amended to do what you want - the code used has been modified as shown below:

    
    
    Option Explicit
    
    
    Private Sub ProcessNames()
    
        Const sSEPARATOR    As String = " "
    
        Dim iNoOfColumns    As Integer
        Dim sThirdName      As String
        Dim rNewCell        As Range
        Dim vaNames         As Variant
        Dim rCell           As Range
    
        For Each rCell In Selection.Cells
    
    '       Add a separator character at the end of the string
    '       to ensure that the Split method works correctly
            rCell.Value = rCell.Value & sSEPARATOR
    
            vaNames = Split(rCell.Value, sSEPARATOR)
            iNoOfColumns = UBound(vaNames)
    
    '       Insert the Name "components" into the adjacent cells
            With rCell.Offset(0, 1)
    
                Range(.Cells(1, 1), _
                      .Cells(1, iNoOfColumns)).Value = vaNames
    
            End With
    
    '       Remove the comma character at the end of the surname
            Set rNewCell = rCell.Offset(0, 1)
            rNewCell.Value = Replace(rNewCell.Value, ",", vbNullString)
    
            Set rNewCell = rCell.Offset(0, 3)
            sThirdName = rNewCell.Value
    
    '       Proceed only if the third "component" (initial) of the Name is non-blank
            If Len(sThirdName) > 0 Then
    
    '           Allow a single initial followed by a full stop . . .
                If Len(sThirdName) = 2 And _
                   Right$(sThirdName, 1) = "." Then
    
                        rNewCell.Value = sThirdName
    
    '           . . . or else allow a single initial
                ElseIf Len(sThirdName) = 1 Then
    
                        rNewCell.Value = sThirdName
    
    '           . . . if the third "component" is not a single initial
    '           then append it to the First Name value
                Else:   rNewCell.Value = vbNullString
                        Set rNewCell = rCell.Offset(0, 2)
                        rNewCell.Value = rNewCell.Value & sSEPARATOR & sThirdName
    
                End If
    
            End If
    
        Next rCell
    
    End Sub

    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Extracting Middle Initial (if present)

    I have pasted the formula for you.

    Formula for B2 to D6 = =TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",100)),1+(COLUMN()-2)*100,100))
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-03-2021
    Location
    Boise, ID
    MS-Off Ver
    Office 2016
    Posts
    7

    Re: Extracting Middle Initial (if present)

    Thank you both, this is just what I needed. You are absolute live savers!

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Extracting Middle Initial (if present)

    Hi again,

    Many thanks for your very prompt feedback.

    You're welcome - glad I was able to help.

    Regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 09-14-2016, 04:55 AM
  2. Replies: 3
    Last Post: 03-05-2015, 02:33 PM
  3. Replies: 7
    Last Post: 05-23-2013, 05:20 PM
  4. Extracting the Middle Initial/Middle Name
    By akwishestofish in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-16-2012, 11:13 AM
  5. Replies: 3
    Last Post: 03-09-2012, 03:19 PM
  6. Replies: 3
    Last Post: 11-21-2010, 10:22 PM
  7. Remove middle initial from "first name middle initial"
    By Justin F. in forum Excel General
    Replies: 15
    Last Post: 09-26-2005, 02:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1