+ Reply to Thread
Results 1 to 15 of 15

Extracting a word from a cell!

  1. #1
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Extracting a word from a cell!

    Hi Super Excelers

    I am looking for special a Excel formula, to extract a string out of a cell.

    This string (alphanumeric code) comes in two forms, which always starts with the letter S.
    It is either 10 or 11 characters long.
    Here is an example; SA9010001, SA9010001W, SX0512001, SX0512001L

    The cells could contain a sentence. ie. [This code SA9010001 is unavailable.]

    THANK YOU
    Last edited by virsilens; 02-22-2018 at 05:42 PM.

  2. #2
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.83 (24031120))
    Posts
    8,732

    Re: Extracting a word from a cell!

    is the S at the start of the character screen and does it always have a space at the end ?

    can you give some example of real data where its correct and where its wrong

    perhaps a spreadsheet sample attached

    what comes to mind is using a test

    left(cell, 1+="S"
    AND
    find(" ",cell,1) = 10
    OR
    find(" ",cell,1) = 10

    if those conditions are all TRUE then you can use in an IF

    =IFERROR(AND(LEFT(A2,1)="S",OR(FIND(" ",A2,1)=11,FIND(" ",A2,1)=12)),"none")
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Extracting a word from a cell!

    Hi ETAF! Thank you for looking.

    Screenshot and file attached

    4299 2018-02-22.jpg

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Extracting a word from a cell!

    This formula will extract your string. However, it will not work if there is any other word that begins with uppercase S in the sentence.

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


    So it works for your example, but it would not work for

    This Service code SA9010001 is unavailable.

    In such as case the formula would return the word "Service".

    (You can get a more sophisticated solution with a macro that uses regex pattern matching.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Extracting a word from a cell!

    file attach
    Attached Files Attached Files

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Extracting a word from a cell!

    We posted at the same time, and I did not see your sample data/results. You have examples where a string begins with S but you show a result of "none". In spite of your example of a sentence, your data shows cells with only the number, and my formula does not work with those. All of these requirements are difficult to do with formulas. I would suggest the macro approach.

    Also, an image attachment has very little value. Just attach the Excel file. It's easier than taking a screenshot first and then attaching that.

    It will be much easier to understand your problem if you provide your file. This allows us to see and experiment with your data, layout, formulas, code, and possibly attach a file with a completed solution. If you are looking for formulas to produce a desired result, it helps if you create a mock-up of what you want the result to look like. Otherwise we would have to build something from scratch, trying to guess what you want it to look like.

    The paper clip icon does not work for attachments. Instead, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.

  7. #7
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Extracting a word from a cell!

    Thanks 6StringJazzer

    I have uploaded the sheet now. I added some better description in adjacent columns.

    The formula pulls out any 10 or 11 digit string that starts with capital S; regardless of word position in a sentence.
    Attached Files Attached Files

  8. #8
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Extracting a word from a cell!

    B2
    PHP Code: 
    =IFERROR(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),(MATCH(1,MMULT((LEN(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),(ROW(INDIRECT("1:"&LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1))-1)*LEN(A2)+1,LEN(A2))))={10,11})*(MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),(ROW(INDIRECT("1:"&LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1))-1)*LEN(A2)+1,LEN(A2)))&"           "&1/17))<12),{1;1}),0)-1)*LEN(A2)+1,LEN(A2))),""
    Try this array formula and copy towards down

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  9. #9
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Extracting a word from a cell!

    Holy mackerel! That's an impressive code nflsales.

    Though it doesn't quite work when I enter it (as array).

    Reattached file with your formula inserted.

    4301 2018-02-22.jpg
    Attached Files Attached Files

  10. #10
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Extracting a word from a cell!

    sorry &" "& (those are actually 11 spaces, when posting here it show as 1 space) was displaying as &" "& in the my above post
    see the attached file
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,900

    Re: Extracting a word from a cell!

    Try this ...

    =IFERROR(LOOKUP(2,1/(MID(A2,ROW(INDIRECT("1:"&LEN(A2)-9)),1)="S")/MID(A2,ROW(INDIRECT("3:"&LEN(A2)-7)),8)/
    (MID(A2&" ",ROW(INDIRECT("11:"&LEN(A2)+1)),1)=" "),MID(A2,ROW(INDIRECT("1:"&LEN(A2)-9)),10)),
    LOOKUP(2,1/(MID(A2,ROW(INDIRECT("1:"&LEN(A2)-9)),1)="S")/MID(A2,ROW(INDIRECT("3:"&LEN(A2)-7)),8)/
    (MID(A2&" ",ROW(INDIRECT("12:"&LEN(A2)+1)),1)=" "),MID(A2,ROW(INDIRECT("1:"&LEN(A2)-9)),11)))

  12. #12
    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: Extracting a word from a cell!

    Try this
    Enter in B2 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 VALUE RESULT
    2 SC13000010 SC13000010
    3 SC13000010-10
    4 S389010426X S389010426X
    5 SERV009087-10
    6 S389010001 LINER - BLACK S389010001
    7 SB96000010L OEM FG SB96000010L
    8 SERV009087-10 OEM FG SERV009087
    9 CATALOG S496010001X ONE STEP FIN S496010001X
    10 DELUXE PERLIN SC09040420L SC09040420L
    11 THE FOX RUNS
    Attached Files Attached Files
    Last edited by AlKey; 02-22-2018 at 09:25 PM.
    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

  13. #13
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Extracting a word from a cell!

    aOmGnON_700b.jpg

    Phuocam and AlKey! both work perfectly

    Good shot at it nflsales, even with the spaces, I couldn't make it happen, prob something on my side.

  14. #14
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,900

    Re: Extracting a word from a cell!

    A2 = S1 SC13000010 AlKey's formula result S1,
    Last edited by Phuocam; 02-22-2018 at 09:53 PM.

  15. #15
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Extracting a word from a cell!

    SOLVED - thanks all!

+ 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. Extracting data from excel to word. Different versions of MS Word giving issues.
    By aritradey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 09:46 AM
  2. [SOLVED] Extracting a word from a cell
    By Fletch74 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-25-2013, 01:47 AM
  3. [SOLVED] Extracting word for number of specific lenth to other cell
    By parajf in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-11-2012, 09:51 PM
  4. Replies: 0
    Last Post: 06-15-2011, 02:22 PM
  5. Extracting a Word from a cell that contains a sentence
    By onuwayhid in forum Excel General
    Replies: 1
    Last Post: 02-07-2008, 12:43 PM
  6. Extracting specific word in a cell
    By Conditional Formatting in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-14-2006, 06:00 PM
  7. Extracting All But Last Word
    By Steve Madden in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-16-2006, 01:25 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