+ Reply to Thread
Results 1 to 12 of 12

Split cell text with variable spaces

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Split cell text with variable spaces

    I have a column of cells and each cell follows the following format: <number><dash><name>

    For example: 2-Henry, and 7-Elizabeth

    I need to extract just the name and not the number or dash - the problem is that the original author occasionally placed a space either after, before or both after & before the dash, so some entries look like: 4- Tom or 6 -Bob, or even 8 - Mary.

    Is there a way to extract just the name when the range of cells are not uniform in the spacing?

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Split cell text with variable spaces

    Can there be more than one name in a cell?
    Can you post a sample of possible configurations for us?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Split cell text with variable spaces

    Not more than one name, but of course the name lengths vary in character length. Too much sanitizing to post the workbook, but if needed, I could write a sample and post it, though it would pretty much be the text samples in my original post copied to a column of cells...

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Split cell text with variable spaces

    If your format is always like that, and the numbers are only 1 character, this should work for you...
    =MID(A1,2+LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1,99)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Split cell text with variable spaces

    Try this

    =TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",25)),25))

    Row\Col
    A
    B
    1
    2-Henry Henry
    2
    7-Elizabeth Elizabeth
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Split cell text with variable spaces

    OK
    with these values in A1:A5
    2-Henry
    4- Tom
    6 -Bob
    8 - Mary
    7-Elizabeth

    This formula, copied down, extracts the name after the dash
    Please Login or Register  to view this content.
    for those values, these are the results:
    Henry
    Tom
    Bob
    Mary
    Elizabeth

    Is that something you can work with?

  7. #7
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Split cell text with variable spaces

    Quote Originally Posted by FDibbins View Post
    If ... the numbers are only 1 character
    The numbers repeat at uneven intervals but are sequential, so I have four number 1's, the and three number 2's, five number 3's, etc... but then they do reach double digits, for example, 10- <space> Adam, and 11-Carrie (no spaces), and 11 -Garrett.

    But I think I can use your formula and change it at the point where the double digits begin (it doesn't grow to triple digits)... how would the formula look to handle double digits?

  8. #8
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Split cell text with variable spaces

    Quote Originally Posted by Ron Coderre View Post
    OK
    with these values in A1:A5
    2-Henry
    4- Tom
    6 -Bob
    8 - Mary
    7-Elizabeth

    This formula, copied down, extracts the name after the dash
    Please Login or Register  to view this content.
    for those values, these are the results:
    Henry
    Tom
    Bob
    Mary
    Elizabeth

    Is that something you can work with?
    Sorry didn't see this before FDibbins' reply - I'll give it a try!

  9. #9
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Split cell text with variable spaces

    Both Ron's and Alkey's (which were variations on the same principle) worked. Thanks guys!!!

    -HeyInKy

  10. #10
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Split cell text with variable spaces

    Thank you for the feedback!

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Split cell text with variable spaces

    I prefer the other's suggestions, I could adjust mine to cater for extra numbers, but they have it for you

  12. #12
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Split cell text with variable spaces

    Yes - but thanks FDibbins - you've *always* been helpful!!

+ 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. [SOLVED] How to split a string up with multiple sized spaces?
    By Sean Thomas in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-07-2012, 06:28 PM
  2. Split Text with spaces when Upper case is encountered
    By KarthikR in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-22-2012, 08:40 AM
  3. SPLIT function on string with multiple spaces
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2011, 08:22 AM
  4. [SOLVED] Using Split Function on String with no spaces
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-09-2006, 11:15 AM
  5. Split numbers with spaces
    By APD in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-20-2005, 01:55 AM

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