jonbowen

Q: I'd like to separate a full name into multiple cells.

I'd like to separate a full name, for instance, Robert A. Clarke Jr. which is located in one cell into four separate cells.

 

  • First name
  • Middle name
  • Last name
  • Suffix

 

I have about 100 names that I need to separate and it would be too tedious to do it individually. The names are separated by spaces. Help!

 

Owner1Owner2
Leah C CrostaJohn E Crosta Jr
Robert A Clarke Jr

MacBook Pro (Retina, 15-inch, Late 2013), OS X Yosemite (10.10.5)

Posted on Jun 1, 2016 6:19 AM

Close

Q: I'd like to separate a full name into multiple cells.

  • All replies
  • Helpful answers

  • by Barry,

    Barry Barry Jun 1, 2016 10:39 AM in response to jonbowen
    Level 7 (32,714 points)
    iWork
    Jun 1, 2016 10:39 AM in response to jonbowen

    HI Jon,

     

    Here's one way:

    • Select all of the cells containing names*
    • Copy
    • Open a new Numbers document**
    • Click the T button to insert a Text box.
    • Click in the text box and Paste
    • Press command-F to open the Find dialogue.
    • Click the v beside the gear and choose Find and Replace from the menu.
    • Click in the Find box. Type a single space.
    • Click in the Replace box. Press option-tab to place a single tab character in the box.
    • Click Replace All.

      This replaces all the spaces with tabs.

    • Click in the text box, press command-A to select All, Copy.
    • Click in the top left non-header cell in the empty table of this new document. Paste.
    • Check the results and adjust as necessary.***

     

    My results with your sample data shown here:

    Screen Shot 2016-06-01 at 10.06.27 AM.png

    Notes:

    * Issues like the placement of John's name may make it easier to handle each column of names separately. First column pasted after selecting (single click) A2 (on this table with no header column) and pasting, Second column pasted after selecting E2.

     

    ** Find will find all of the spaces in the document. Replace All will replace all of those spaces. Placing the copied list on a separate document preserves the original data until you want to change it.

     

    *** Generally, the adjustment will consist of locating entries (like the first row above) where one name (John's) is in the wrong columns. The adjustment consists of selecting the first item out of place, and all items of that name lying to the right, then clicking and dragging the first item to the right and dropping it in the same row of the correct column.

    More than one line can be adjusted at the same time, but only if they can be selected in a single group, and all start in the same column. Sorting on columns with empty cells that should contain data can be used to gather rows needing the same adjustment together for a bulk move to the correct locations.

    Example:

    Sorting the new table on column C will bring all lines with no entry in this column into a group either at the top or the bottom of the list. These will be the single names (no entry in the 'second owner' column) with only a first name and surname (no middle name or middle initial). Select all the surnames in column B, then click on the top one and drag it (and the rest) one column to the right, dropping it on the same row of column C.

     

    Regards,

    Barry

  • by SGIII,

    SGIII SGIII Jun 2, 2016 3:42 PM in response to jonbowen
    Level 6 (10,796 points)
    Mac OS X
    Jun 2, 2016 3:42 PM in response to jonbowen

    A script can be efficient at this sort of task (no scripting knowledge needed to use; just copy-paste).

     

    Screen Shot 2016-06-02 at 6.30.38 PM.png

     

    To use:

     

    1. Copy-paste the script below into Script Editor (in Applications > Utilities).
    2. Select the cells with the names to split (in this example A2:A6).
    3. Command-c to copy the contents of the cells to the clipboard.
    4. Click the triangle 'run' button in Script Editor.
    5. Click once in an upper-left destination cell (in this example C2) and command-v to paste.

     

    You're done in less than a minute.

     

    SG

     

    set theList to paragraphs of (the clipboard as «class utf8»)

    set pasteStr to ""

    repeat with i in theList's items

      set {firstName, middleInit, lastName, theSuffix} to {"", "", "", ""}

      tell i

      set firstName to word 1

      if (word 2's length > 1) and (i's words)'s length ≥ 2 then

      set lastName to word 2

      try

      set theSuffix to word 3

      end try

      else

      set middleInit to word 2

      set lastName to word 3

      try

      set theSuffix to word 4

      end try

      end if

     

      end tell

      set pasteStr to pasteStr & ¬

      firstName & tab & middleInit & tab & lastName & tab & theSuffix & return

    end repeat

    set the clipboard to pasteStr

    return pasteStr

  • by Barry,

    Barry Barry Jun 2, 2016 11:02 PM in response to SGIII
    Level 7 (32,714 points)
    iWork
    Jun 2, 2016 11:02 PM in response to SGIII

    Hi SG,

     

    You wrote:

    if (word 2's length > 1) and (i's words)'s length ≥ 2 then

      set lastName to word 2

      try

      set theSuffix to word 3

      end try

      else

      set middleInit to word 2

      set lastName to word 3

      try

      set theSuffix to word 4

      end try

      end if

     

    Nicely handled!

     

    Barry

     

     

     

     



  • by SGIII,

    SGIII SGIII Jun 3, 2016 1:10 PM in response to Barry
    Level 6 (10,796 points)
    Mac OS X
    Jun 3, 2016 1:10 PM in response to Barry

    Thanks, Barry.  Sometimes AppleScript can seem logical.

     

    SG

  • by AG.EC,

    AG.EC AG.EC Sep 26, 2016 9:15 AM in response to SGIII
    Level 1 (4 points)
    Sep 26, 2016 9:15 AM in response to SGIII

    Hi SGIII,

     

    I wanted to use your suggestion of a script to sort my names, but the format for the list of names I want to sort is:  last name, first name.  I want to break up the name into two separate cells.  Can you help?

  • by Barry,

    Barry Barry Sep 26, 2016 11:07 AM in response to AG.EC
    Level 7 (32,714 points)
    iWork
    Sep 26, 2016 11:07 AM in response to AG.EC

    Hi AG,

     

    I'll leave the script editing to SG, but he may find some additional information useful:

    • Do all the names in the list have the same format: last, first
    • Are there any hyphenated names: eg. Smith-Jones, Jane
    • Any titles/honorifics: Anderson, Dr. Allison
    • Any suffixes/degrees: Cooper, John, LLB QC
    • Any other diversions from the basic pattern?

    • Which order do you want the results: Last   First  or  First  Last

     

    Regards,

    Barry

  • by SGIII,

    SGIII SGIII Sep 26, 2016 12:05 PM in response to AG.EC
    Level 6 (10,796 points)
    Mac OS X
    Sep 26, 2016 12:05 PM in response to AG.EC

    Did you try the script? It breaks up the name into separate cells so you can sort them however you want in Numbers.

     

    SG