+ Reply to Thread
Results 1 to 9 of 9

Sum of each cell having text string required in separate cell.

  1. #1
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Post Sum of each cell having text string required in separate cell.

    I need sum of each cell
    I have tried multiple options but not able to
    Actually there are different text symbols like "+", "(", ")", and space
    I am stuck using Search / Find Function locating only one text symbol

    Cell values are like
    B3: 54 + 216 + 20
    B4: 5 + 148 + 87 + 5
    B5: 48 + (4+3) + 349 + 4

    Result required is
    C3: 290
    C4: 245
    C5: 166
    Attached Files Attached Files

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Sum of each cell having text string required in separate cell.

    There is a VBA function called EVALUATE that will, well, evaluate math strings like the examples you provided. Try this:

    Open the VB Editor (ALT+F11)
    Click Insert > Module
    In the new module, paste the following code:
    Please Login or Register  to view this content.
    Close the VB Editor window
    In cell C3, put the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    It should calculate the correct value. I tested on your other examples in your test workbook, and it worked each time.

    Good luck!

  3. #3
    Forum Expert dosydos's Avatar
    Join Date
    12-09-2015
    Location
    Massachusetts
    MS-Off Ver
    365(PC) V:2308
    Posts
    1,474

    Re: Sum of each cell having text string required in separate cell.

    The only way i know how is to use name manager.
    Select cell D3.
    Then select NAME MANAGER from formula ribbon
    Click New...
    Name: Evaluate

    Refers TO: =EVALUATE(SUBSTITUTE(Sheet1!B3," ",))

    Hit ok.
    in D3 type =evaluate and hit enter. Drag formula down
    Attached Images Attached Images
    <----- If you are happy with your solution please click on the "* Add Reputation" as a way to say thank you.

  4. #4
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Sum of each cell having text string required in separate cell.

    Quote Originally Posted by Paul View Post
    There is a VBA function called EVALUATE that will, well, evaluate math strings like the examples you provided. Try this:

    Open the VB Editor (ALT+F11)
    Click Insert > Module
    In the new module, paste the following code:
    Please Login or Register  to view this content.
    Close the VB Editor window
    In cell C3, put the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    It should calculate the correct value. I tested on your other examples in your test workbook, and it worked each time.

    Good luck!
    Thanks but I am not good with VBA, Is it possible to use functions or multiple functions in formula to resolve this?

  5. #5
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Sum of each cell having text string required in separate cell.

    Quote Originally Posted by dosydos View Post
    The only way i know how is to use name manager.
    Select cell D3.
    Then select NAME MANAGER from formula ribbon
    Click New...
    Name: Evaluate

    Refers TO: =EVALUATE(SUBSTITUTE(Sheet1!B3," ",))

    Hit ok.
    in D3 type =evaluate and hit enter. Drag formula down

    Yes this perfectly works, but the problem here is I can't move the sum value to another column, for that I have to use Name Manager each time I am moving Total to a different column, that is why I am looking for a formula, that is easy to copy and paste to different cells.

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Sum of each cell having text string required in separate cell.

    You don't have to be good with VBA, you just have to follow the instructions I gave you ONE TIME. Save the file as an Excel Macro-enabled file (.xlsm) and that's it. Use the new =sum_text(cell) function anywhere within that workbook.

    If you need the custom function in another workbook, open that one > insert a module > paste the code. You just need to save the files containing the function as .xlsm so it retains the code.

    Performing math on text is not a natural feature in most programs, so you'll have to weight the pros and cons of spending an extra few seconds on some tasks.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Sum of each cell having text string required in separate cell.

    And as for dosydos's solution, the Name Manager function you create can (and should be) relative to the current cell you're in.

    https://superuser.com/questions/2533...were-a-formula (See answer from Laurentiu Mirica on Jun 27 '14 at 13:08)

    Let's assume your string is in B3, and you're currently active cell is C3. When you go into Name Manager and create the new name (e.g. eval) and set the 'Refers to:' field to =EVALUATE(B3), you can then use the function

    =eval

    anywhere in the spreadsheet and it will reference the cell immediately to the left of that cell. (If you use it in column A you'll get an error, of course.)
    Last edited by Paul; 02-19-2020 at 05:21 PM.

  8. #8
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Sum of each cell having text string required in separate cell.

    Issue - Evaluate.JPG

    This is an issue when using Evaluation with Name Manager

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Sum of each cell having text string required in separate cell.

    Save the file as a macro-enabled workbook (.xlsm), the same as if you used my code.

    I believe in older versions of Excel there was a true Evaluate() workbook function, but it's now relegated to VBA. Even the Name Manager version apparently requires VBA references.

+ 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] 2 cell text lookup in text string to return data from separate column
    By Zivhodiva in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-08-2019, 03:03 PM
  2. [SOLVED] Formula or function to separate string of text in a cell to multiple columns
    By Chris McGlothen in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-29-2016, 12:10 PM
  3. [SOLVED] Separate the last word of a string of text in a cell
    By ClaireH in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2013, 06:33 AM
  4. Separate out a text string in one cell, and break into into individual cells
    By StephenHall in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-05-2012, 03:45 PM
  5. Separate numbers embed in a text string into a new column or cell
    By DennyT48 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-23-2012, 04:14 PM
  6. Separate a string of text from a cell
    By albardit18 in forum Excel General
    Replies: 7
    Last Post: 06-03-2011, 04:22 PM
  7. Replies: 4
    Last Post: 01-17-2011, 11:44 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