+ Reply to Thread
Results 1 to 6 of 6

Function to calculate a string with formula.

  1. #1
    Registered User
    Join Date
    06-17-2014
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    16

    Function to calculate a string with formula.

    Hi all, a string in a cell A1 is "4000 + 200", without using VBA, how to convert it to a value? Thanks.
    3.xlsx

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Function to calculate a string with formula.

    A bit long-winded, but try this (It allows for variable length values)...
    =LEFT(A1,FIND("+",A1,1)-2)+MID(A1,FIND("+",A1,1)+2,99)

    If they will always be in that format...
    =LEFT(A1,4)+RIGHT(A1,3)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

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

    Re: Function to calculate a string with formula.

    hi csleong. try this array formula:
    =SUM(IFERROR(--MID(SUBSTITUTE(A1," + ",REPT(" ",LEN(A1))),(ROW($1:$111)-1)*LEN(A1)+1,LEN(A1)),""))


    ...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. Press F2 on that cell and try again.

    it's explained in the file of my link below*Tips & Tutorials I Compiled, sheet 54. the EVALUATE option needs to be macro enabled

    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
    Registered User
    Join Date
    06-17-2014
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    16

    Re: Function to calculate a string with formula.

    Thank you! both solution works fine for me, but Benishiryo's can work even further!
    Just a question I want to ask Benishiryo, what is the function of this "--" in the equation?

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Function to calculate a string with formula.

    LEFT/MID/RIGHT all create a text answer, even if it looks like a number.

    There are a few ways to convert the text back to a number -
    add 0 to it
    multiply by 1
    use a double negative, which 1st converts to a new value (same as adding 0), then uses the 2nd neg to swap the answer back to a pos value

  6. #6
    Registered User
    Join Date
    06-17-2014
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    16

    Re: Function to calculate a string with formula.

    Thanks FDibbins.

+ 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. Calculate row number with row() function and use it in existing formula
    By bluerabbit in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-12-2013, 10:15 AM
  2. MID function formula string extract problem
    By ExcelNewby in forum Excel General
    Replies: 3
    Last Post: 02-22-2009, 06:36 AM
  3. Formula string vs. workbook function VBA for speed
    By inwalkedbud in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2008, 09:19 AM
  4. [SOLVED] Looking for function or formula to calculate number that is revers
    By Ken in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-07-2005, 08:06 AM
  5. Need Formula or Function to calculate Margin (reverse of Percent a
    By Ken in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-07-2005, 06:06 AM

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