+ Reply to Thread
Results 1 to 12 of 12

Help to extract partial text from a cell

  1. #1
    Registered User
    Join Date
    12-12-2014
    Location
    UK
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Help to extract partial text from a cell

    I'd like to know how to extract a specific number from a cell in a table that looks something like this:

    Cell A1:
    Movement Disorder (12)
    Parkinson's Disease (4)
    Multiple Sclerosis (5)
    Stroke (1)

    Cell A2:
    Alzheimer's Disease (2)
    Multiple Sclerosis (3)
    Pain (7)

    Text Extraction.xlsx

    For each row I want to extract the number in parentheses that follows 'Multiple Sclerosis'. I found a clunky way of doing this using MID, FIND and LEFT functions, but it took me 2 separate formulas to get what I needed. I would like to be able to achieve this in one step. The issue I'm coming up against is that I can't use "(" and ")" to identify the starting points because there are multiple instances of these, and my search term is not always preceded or followed by the same term.

    I've attached the workbook I created so far with my clunky formulas. Can anyone suggest a better way to do this?

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Help to extract partial text from a cell

    Hello and welcome to the forum,

    As a general rule of thumb, you have to be able to set 'rules' to guide any formula or macro to run; they are not inherently intuitive. You can always set multiple rules in a hierarchical fashion so that for example:

    1. the number comes between parentheses right after the term "Multiple Sclerosis"... if not then...
    2. the number comes right after "Multiple Sclerosis"... if not then...
    3. the number comes right after "MS"... etc.

    If you can't dictate a logical sequence because the data will be completely random then the results will also be completely random.

    Having said that, can you provide us with logical If then statements with before/ after examples.

    Thanks.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

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

    Re: Help to extract partial text from a cell

    Using your posted workbook, this regular formula pulls the count for the I2 value
    Please Login or Register  to view this content.
    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Help to extract partial text from a cell

    Hi Ron,

    I think the OP is looking for only the number after a specific disease, but the way it's presented can different from cell to cell.

  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: Help to extract partial text from a cell

    Maybe this

    =LOOKUP(2^15,-LEFT(MID(C2,SEARCH("Multiple Sclerosis ",C2)+LEN("Multiple Sclerosis "),10),{1,2,3,4,5,6,7,8,9,0}))

    Or

    =SUBSTITUTE(MID(C2,SEARCH("Multiple Sclerosis ",C2)+LEN("Multiple Sclerosis ("),3),")","")
    Last edited by AlKey; 12-12-2014 at 11:05 AM.
    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: Help to extract partial text from a cell

    Perhaps I didn't explain the formula I posted correctly...
    It finds the search text and returns the number in parentheses after that text.

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

    Re: Help to extract partial text from a cell

    Using your posted workbook, this regular formula pulls the count for the I2 value
    EDITED TO CLARIFY:
    This formula finds the search text (in cell I1) in the Disease Areas column and returns the number in parentheses after that text. If the search text does not exist in the referenced cell, the formula returns 0.
    Please Login or Register  to view this content.
    Is that something you can work with?
    Last edited by Ron Coderre; 12-12-2014 at 11:25 AM.

  8. #8
    Registered User
    Join Date
    12-12-2014
    Location
    UK
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Re: Help to extract partial text from a cell

    Abousetta - here are some logical statements about what I am searching for:
    • Multiple Sclerosis will always be spelled out in full (not abbreviated to MS)
    • The number I am looking for will always be contained within brackets after 'Multiple Sclerosis '
    • The term Multiple Sclerosis may appear anywhere in the list
    • Other items in the list vary from row to row

    Ron - thank you, that formula does work. But I'd like to understand it better. I'm not familiar with the 10^10 notation or the {1,2,3...etc}

    I've just seen other replies to my OP as well so reviewing those now

  9. #9
    Registered User
    Join Date
    12-12-2014
    Location
    UK
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Re: Help to extract partial text from a cell

    Quote Originally Posted by AlKey View Post
    =SUBSTITUTE(MID(C2,SEARCH("Multiple Sclerosis ",C2)+LEN("Multiple Sclerosis ("),3),")","")
    This works great too, thank you! I haven't come across SUBSTITUTE before. Will go and look up.

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

    Re: Help to extract partial text from a cell

    In the formula I posted: =IFERROR(LOOKUP(10^10,--LEFT(MID(C2,SEARCH($I$1,[@[Disease Areas]])+LEN($I$1),10),{1,2,3,4,5,6,7,8})),0)

    This section: LOOKUP(10^10,--LEFT(MID(C2,SEARCH($I$1,[@[Disease Areas]])+LEN($I$1),10),{1,2,3,4,5,6,7,8}))
    takes advantage of a LOOKUP feature(?).

    Regarding an array of numbers,
    1) LOOKUP ignores any error values (#N/A!, #VALUE!, etc)
    2) If the lookup value is greater than the all of the arrayed numbers...it returns the last numeric value

    using Row_2 as an example
    Once this section: MID(C2,SEARCH($I$1,[@[Disease Areas]])+LEN($I$1),10)
    returns: "5)Stroke "

    This part: LEFT(MID(C2,SEARCH($I$1,[@[Disease Areas]])+LEN($I$1),10),{1,2,3,4,5,6,7,8})
    builds an array of the left 1, then 2, then 3, etc. characters and
    returns this array: {"5","5)","5)","5)S","5)St","5)Str","5)Stro","5)Strok"}

    and this part tries to convert each element of that array to a number: --LEFT(MID(C2,SEARCH($I$1,[@[Disease Areas]])+LEN($I$1),10),{1,2,3,4,5,6,7,8})
    resulting in this array: {5,#VALUE!,#VALUE!,#VALUE!,#VALUE!,#VALUE!,#VALUE!,#VALUE!}

    Finally, when the LOOKUP function tries to match 10^10...which is larger than any value you would expect to find...it matches on the last numeric value: 5

    If the Multiple Sclerosis text was this: Multiple Sclerosis (500)
    The resulting array would be this: {5,50,500,#VALUE!,#VALUE!,#VALUE!,#VALUE!,#VALUE!}
    so the LOOKUP match would be 500

    I hope that helps.

  11. #11
    Registered User
    Join Date
    12-12-2014
    Location
    UK
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Re: Help to extract partial text from a cell

    Thank you all for your helpful and very quick suggestions.

    I am going to move forward with the formula suggested by AlKey:
    =SUBSTITUTE(MID(C2,SEARCH("Multiple Sclerosis ",C2)+LEN("Multiple Sclerosis ("),3),")","")

    It is basically an extension of the first formula I was using, with the addition of the SUBSTITUTE to remove the unwanted ")". I know that this has its limitations, as it won't work if the number has more than 3 digits, but I am fairly confident that in the datasets I will be working with, the numbers will never be higher than 999.

    Ron - I realise your suggestion is more technically correct, but I prefer to use something that I understand better. I am sure that with a bit more concentration I could figure it all out, but its after 5pm on a Friday and my brain has switched off for the weekend! Ha!

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

    Re: Help to extract partial text from a cell

    All that matters is that you get something that works that you feel comfortable using. I'm glad you got that.

+ 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] Find Partial text in an array and extract charaters to right
    By jenita.kurlawala in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-02-2013, 08:03 AM
  2. [SOLVED] extract partial string from Cell
    By sydcoco in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-28-2013, 12:34 AM
  3. Extract partial content from a single cell
    By mildredtpeabody in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-21-2013, 06:39 PM
  4. matching partial text within one cell to partial text within another
    By Solstice in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 03-03-2010, 09:13 PM
  5. [SOLVED] formula to extract partial content (text) of cell
    By milano in forum Excel General
    Replies: 3
    Last Post: 11-09-2005, 01:00 PM

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