+ Reply to Thread
Results 1 to 6 of 6

Extract specific text within a text string

  1. #1
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Extract specific text within a text string

    Hi,

    I have a list that contains dosages of drugs however the dosage appears in different parts of the text string. For instance:

    Drug A 50mg twice a day
    50mg Drug B Once a day
    50 mg Drug C twice a day
    Twice a day Drug D 50mg

    In the column next to the list, I would like to extract just the drug dosage (wherever it appears in the text string). I've been play around with the left, right and search functions but can't get it to work without pulling in other parts of the text (ideally one formula that looks for all the combinations would be great).

    list 2.jpg

    Thanks in advance

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Extract specific text within a text string

    This works for the small sample that you shared.

    B2 =TRIM(MID(A2,MAX(SEARCH("mg",A2)-3,1),5))

  3. #3
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Extract specific text within a text string

    That's perfect, thanks so much. What if it was a single number like 2mg or 2 mg (with a space in the middle)?

  4. #4
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Extract specific text within a text string

    This is often the case with requests like this.

    The best way to go about building a formula that will work for all cases would be to make your sample more representative of your actual data.

    That being said, you can try this monster:

    =LEFT(SUBSTITUTE(A2,LEFT(A2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))-1),""),SEARCH("mg",SUBSTITUTE(A2,LEFT(A2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))-1),""))+1)

  5. #5
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Extract specific text within a text string

    Wow that is a monster, brilliant!
    Thanks so much

  6. #6
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Extract specific text within a text string

    You're welcome. Thanks for the rep!

+ 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. Extract Specific Text From String
    By dawsexcel in forum Excel General
    Replies: 3
    Last Post: 07-13-2016, 01:44 PM
  2. Extract/return specific text from cell/string
    By JE2BD in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-02-2015, 05:32 PM
  3. Extract specific numbers from a string of text
    By Galwaygirl13 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-19-2012, 03:22 PM
  4. Extract specific word from a text string
    By krjoshi in forum Excel General
    Replies: 10
    Last Post: 01-19-2012, 02:00 PM
  5. Replies: 11
    Last Post: 09-29-2011, 04:42 AM
  6. Replies: 5
    Last Post: 05-03-2011, 09:35 AM
  7. [SOLVED] Extract specific value from a long text string
    By Dinesh in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-10-2006, 11:30 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