+ Reply to Thread
Results 1 to 7 of 7

Look for the first space from the right side of a cell

  1. #1
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Look for the first space from the right side of a cell

    Hello all,

    I am trying to remove the text from a string from the right side of a cell. Basically it will start from the right and look for the first space (" ") and then it will copy those characters into the next coulum and then remove them from the original string in the original cell. I have attached an example of what I am trying to accomplish. With the original text in coloum A.

    Your help would be greatly appreciated.

    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Look for the first space from the right side of a cell

    I think you need something like this :
    =RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

    Edit-
    see attachment
    Attached Files Attached Files
    Last edited by dredwolf; 02-19-2013 at 07:14 PM.
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  3. #3
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Look for the first space from the right side of a cell

    hi there. if all you wanted to do was to achieve column D, then:
    =SUBSTITUTE(A1," "," #",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))

    if you need column B, then maybe:
    =LEFT(A1,FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))-1)

    to find the characters after the last space, you can use dredwolf's. if your last space of your data is consistently after " B ", then the formula could be slightly shorter.

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  4. #4
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Look for the first space from the right side of a cell

    Correction to my original File :New Microsoft Excel Worksheetsol2.xlsx

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

    Re: Look for the first space from the right side of a cell

    Hi whatsmyname

    Another option:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If you need the text in columns B & C, You can do Text to Columns > Fixed Width > Position the break lines.
    Regards Kevin


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

  6. #6
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Re: Look for the first space from the right side of a cell

    Wow,

    Thank you all! dredwolf, can you explain your formula in detail for me? All of these options work great. I just would like to understand the formulas so I can learn myself. Also, dredwolf, how did you get it to automatically fill in columns B,C, & D, after the string is entered into column A?

  7. #7
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Look for the first space from the right side of a cell

    Okay, Using the revised Formulas posted in Second workbook
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    B1 formula
    LEN(A1)-LEN(SUBSTITUTE(A1," ","")); this calculates how many spaces are in the string in A1 by taking the length of a1 with spaces and subtracting the lenght of the string with no spaces (the substitute replaced all the spaces with nothing("")), this gives us the number of the space to Substitute with the '~' in this :SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))) ( the blue part is the optional paramater for Substitute telling it which occurrence of the 'old text'(" ") to replace with 'new text'("~"))
    The LEFT(A1,FIND("~",.. part tells Excel to take the Left part af A1, with the find("~",....)-1) telling it how many characters to use
    SO.. "Find the position of the tilde in the modified(through the substitutes) A1 String,subtract 1, and return that many of the characters from the Left of A1"

    C1 formula
    is pretty much the same, but for the right side of A1
    we want all the characters Beyond the last space, so return Lenght of A1 minus the position of the "~"(last space) # of characters from the end of A1

    D1 formula
    This simply Creates the new string from the results : "take B1 add " #" to the end of that, then add C1 to the end of that" (the '&' is a shortcut for concatenate)

    The way the auto fill works is because of the Relative Addressing (with $A$1(Absolute Addressing), the formula would always look at cell A1),by not using the '$' sign, the A1 changes to A2,A3,A4... as you drag the formulas down the columns

    Hope I didn't confuse you TOO much there

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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