+ Reply to Thread
Results 1 to 8 of 8

Extracting a certain string of text from a cell

  1. #1
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    19

    Extracting a certain string of text from a cell

    Hi everyone,

    Basically, I'm trying to extract a numbers from a cell containing text (for anyone interested, I'm basically trying to get the quantity bought/sold of a stock). For example, in cell A1, I could have the text string:

    SOLD 565 MGNT.MM

    or

    BGHT 10,203,123 M.LN

    Basically, it will start with the the 4-letter words 'SOLD' or 'BGHT' and then a number (of varying length) followed by a string of text of varying length (I think it's between 4 and 7 characters long)

    Is there a way I can extract the number easily?

    I was thinking of using the method shared here (http://www.mrexcel.com/forum/excel-q...xt-string.html) but I don't fully understand the formula. Basically, the number I need (in the above examples, it would be 565 or 10,203,123) always comes after a space.
    Thanks!
    Last edited by Jnap; 07-06-2015 at 02:52 AM.

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

    Re: Extracting a certain string of text from a cell

    =lookup(10^10,mid(substitute(a1,",",""),5,row($1:$10))+0)
    Last edited by samba_ravi; 07-01-2015 at 02:04 PM.
    Samba

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

  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: Extracting a certain string of text from a cell

    With
    A1: a string beginning with 4-letters, a space, then numeric text...followed by a space and other text
    SOLD 565 MGNT.MM


    this formula returns the numeric string
    Please Login or Register  to view this content.
    In that example, the formula returns: 565

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Extracting a certain string of text from a cell

    Thanks for both of your responses.

    I tried Ron's formula and it works perfectly and it is simple enough for me to fully understand!

    I have one further question, if you don't mind. Is there a way to adjust Ron's formula to make the quantity negative if the stock is being sold and make the quantity positive if the stock is being bought.

    For example:

    SOLD 565 MGNT.MM

    Quantity = -565


    BGHT 565 MGNT.MM

    Quantity = 565

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

    Re: Extracting a certain string of text from a cell

    =MID(LEFT(A1,FIND(" ",A1,6)-1),6,100)*IF(COUNTIF(A1,"*sold*"),-1,1)

  6. #6
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Extracting a certain string of text from a cell

    Thank you so much nflsales.

    The current formula I am using is:

    =IF(A9="","",MID(LEFT(A9,FIND(" ",A9,6)-1),6,100))*IF(A9="","",IF(COUNTIF(A9,"*SOLD*"),-1,1))

    With A9 being where the text is.

    If nothing is in A9, the formula displays #VALUE.

    Is there a way to get the cell to be blank (i.e. "") if A9 is empty?

  7. #7
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Extracting a certain string of text from a cell

    Anyone?

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

    Re: Extracting a certain string of text from a cell

    With
    A1: text beginning with either SOLD or BGHT (or blank)

    This formula returns the numeric part after the prefix, converting to negative if the prefix is SOLD. If A1 is blank, the formula returns a text-blank.
    Please Login or Register  to view this content.
    Is that something you can work with?

+ 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 particular data from a string of text in a cell...
    By Reggie A in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-06-2014, 01:04 AM
  2. Extracting particular data from a string of text in a cell...
    By Reggie A in forum Hello..Introduce yourself
    Replies: 3
    Last Post: 08-04-2014, 10:32 PM
  3. Extracting a portion of text string from a cell
    By TKJ in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-30-2013, 12:49 PM
  4. Extracting Text from a string in a Cell (Excel VBA)
    By jimmy_nora in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-22-2010, 05:30 AM
  5. Replies: 2
    Last Post: 09-07-2010, 04:14 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