+ Reply to Thread
Results 1 to 13 of 13

Get the sum from text

  1. #1
    Registered User
    Join Date
    12-01-2016
    Location
    Pune, Maharashtra, India
    MS-Off Ver
    Microsoft Office 2016
    Posts
    13

    Get the sum from text

    Respected Excel Gurus,


    I have a paragraph which contains values. I want the sum of that values.

    Attaching herewith Excel File for reference.

    Thanking you.

    Regards!

    SGK
    Attached Files Attached Files

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Get the sum from text

    Please try
    at F9
    =FILTERXML("<x><m>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($C$3,"worth ","+"),"spent ","-"),CHAR(10)," ")," ","</m><m>")&"</m></x>","//m[contains(., '$')]["&ROWS(F$9:F9)&"]")

    F16
    =SUMPRODUCT(FILTERXML("<x><m>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($C$3,"worth ","+"),"spent ","-"),CHAR(10)," ")," ","</m><m>")&"</m></x>","//m[contains(., '$')]"))

    I differentiate Received and spent by "worth" and "spent".


    Bob got 50 reward points worth $100
    he bought books worth $37

    $37 also with received.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-13-2018
    Location
    Istanbul
    MS-Off Ver
    Microsoft 365
    Posts
    91

    Re: Get the sum from text

    < deleted >
    Last edited by Mgc26133; 01-08-2021 at 02:12 PM.

  4. #4
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Get the sum from text

    a UDF variant, stored in standard VBE module

    Please Login or Register  to view this content.
    could be called as

    =SUM_STRING(C3)

    or, if you needed to customise you could pass parameters explicitly, e.g.:

    =SUM_STRING(C3,"$","BOUGHT|SPENT")

    where:
    the $ denotes the monetary delimiter
    the pipe delimited string would store all terms that represent Expense items and precede the monetary delimiter

    by default, both of the above variants would return the same answer, 75.43, however, if you changed BOUGHT|SPENT to just BOUGHT you would get 150.57 as the SPENT items would then be considered income

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Get the sum from text

    Got the formula from XLent's Logic

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Bo_Ry; 01-07-2021 at 11:20 AM.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Get the sum from text

    Bo_Ry. A lovely piece of work. I am trying to learn FILTERXML... having failed a month or so ago. Both FILTERXML and Bo_Ry are amazingly versatile... Amazingly, I can at least now understand the formula. Whether or not I could reproduce it is another matter entirely.

    Your first solutions on this thread seemed to me to be a bit unstable. It didn't take much intervention to cause the . to appear after the 37 and the 15 and for the values to be returned as left-justified text. This one seems perfect.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  7. #7
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070

    Re: Get the sum from text

    @ XLent

    No Doubt ... Truly EXCELLENT ...!!!

    HTH
    Carim


    Top Excel Links

  8. #8
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Get the sum from text

    @Glenn, Thanks for the rep and very kind comment.

    There are many more XPath syntaxes that I don't understand like " following::, preceding::" that I tried to apply but failed.
    Hopefully, that some XML expert will step in and show me how to use efficiently XPath

    Please check this link for more XPath.
    https://docs.oracle.com/cd/E35413_01..._functions.htm

  9. #9
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Get the sum from text

    Another UDF

    =sumst(C3)

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    12-01-2016
    Location
    Pune, Maharashtra, India
    MS-Off Ver
    Microsoft Office 2016
    Posts
    13

    Re: Get the sum from text

    Bo_Ry Sir,

    Thanking you very much. Genius Work done by you Sir.

    Thanx once again.

    Regards!

    SGK

  11. #11
    Registered User
    Join Date
    12-01-2016
    Location
    Pune, Maharashtra, India
    MS-Off Ver
    Microsoft Office 2016
    Posts
    13

    Re: Get the sum from text

    Mgc26133 Sir,

    Doing the calculation manually in this case is much faster. But what if I have 4 to 5 A4 Size pages which contains values like this.

    Anyway. Thanx very much for your reply.

    Regards!

    SGK

  12. #12
    Registered User
    Join Date
    12-01-2016
    Location
    Pune, Maharashtra, India
    MS-Off Ver
    Microsoft Office 2016
    Posts
    13

    Re: Get the sum from text

    XLent Sir,

    Thanking you very much for reply.

    Regards!

    SGK

  13. #13
    Registered User
    Join Date
    12-01-2016
    Location
    Pune, Maharashtra, India
    MS-Off Ver
    Microsoft Office 2016
    Posts
    13

    Re: Get the sum from text

    Bo_Ry Sir,

    You people are truly, indeed mastermind. Don't have the words. Thanking you very much.

    Regards and Happy New Year to all of you.

    SGK

+ 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 specific text within text and result dependent text in specified column
    By Eftychia in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-08-2019, 08:39 AM
  2. Replies: 1
    Last Post: 10-30-2018, 05:01 AM
  3. Replies: 1
    Last Post: 12-17-2015, 03:35 AM
  4. [SOLVED] Need to Mod Code on red text, I have VBA to distinguish Paid(Black Text) Unpaid(Red Text)
    By Garbology in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2014, 07:55 PM
  5. Replies: 0
    Last Post: 04-22-2013, 12:13 PM
  6. Macro to Parse Text - Import text to Excel from Multiple Text Files & Folders
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2012, 01:05 AM
  7. [SOLVED] Use .text from previous text box in form to prefill text in second text box
    By chromachem in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2012, 10:04 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