+ Reply to Thread
Results 1 to 4 of 4

Text to columns at last space only

Hybrid View

  1. #1
    Registered User
    Join Date
    05-07-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    1

    Text to columns at last space only

    I have a column that has multiple words, mostly names. I need to split them into two columns at the last space.

    Examples:
    Joe Doe
    Joe & Jane Doe
    Philip C. Merry
    My Great Company
    I need to have the names split as follows.

    Column 1       Column 2
    Joe            Doe
    Joe & Jane     Doe
    Philip C.      Merry
    My Great       Company
    My name column is currently starting at B2. I have seen instructions how to split at first space or how to split into First, Last and Middle names but I only need to split at the last space. Thanks in advance for your help.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Text to columns at last space only

    put
    =TRIM(LEFT(SUBSTITUTE(B2," ",REPT(" ",25)),LEN(SUBSTITUTE(B2," ",REPT(" ",25)))-25)) in c2 and
    =TRIM(RIGHT(SUBSTITUTE(B2," ",REPT(" ",25)),25)) in d2
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Text to columns at last space only

    Hi mieuxvivre

    Try the following.
    In D2:
    Formula: copy to clipboard
    =TRIM(RIGHT(SUBSTITUTE(B2," ",REPT(" ",LEN(B2))),LEN(B2)))

    Then in C2:
    Formula: copy to clipboard
    =SUBSTITUTE(B2,D2,"")
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  4. #4
    Registered User
    Join Date
    05-03-2013
    Location
    Navi Mumbai, India
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Text to columns at last space only

    I'm assuming you have placed all the Full Names in Column A starting from Row 2.

    Once you have done that, run the following macro:

    Sub SeparateFirstAndLastName()
        Cells(1, 2).Value = "First Name"
        Cells(1, 3).Value = "Last Name"
        For i = 2 To Sheets(1).UsedRange.Count
            aFullName = Split(Cells(i, 1).Value, " ")
            sFirstName = ""
            For j = 0 To UBound(aFullName)
                If j < UBound(aFullName) Then
                    sFirstName = sFirstName & " " & aFullName(j)
                Else
                    sLastName = aFullName(j)
                End If
            Next
            Cells(i, 2).Value = sFirstName
            Cells(i, 3).Value = sLastName
        Next
    End Sub
    www.LaunchPixels.com
    www.imZeeshan.com

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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