+ Reply to Thread
Results 1 to 28 of 28

Sum of numeric String with Condition

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Sum of numeric String with Condition

    Hello Excel Experts,

    I was able to get help, and just realized that I need to put a condition.

    Given 5 rows in column A, I have strings that has the word 'Qty' and some none. For any string that has the word 'Qty', I want the numeric value before it. For string that doesn't have the word 'Qty', I want it to be 1.

    In column B, I have categories, such as "Excel", "PowerPoint" etc.

    My question is, how should I added the numeric string for Excel without a helper column?

    Column A Column B Comment
    some string name and ended with (4 Qty) PowerPoint not to take (not Excel)
    some string name WITHOUT the word Qty Excel to take numeric 1 BY DEFAULT even though there's no 'Qty' (Excel)
    some string name and ended with (12 Qty) Excel to take numeric 12 (Excel)
    some string name and ended with (3 Qty) Excel to take numeric string 3 (Excel)
    some string name and ended with (5 Qty) Word not to take (not Excel)

    In the above example, I would like to have an answer in say cell C1 to be 16

    Edit: People assume that I wanted to extract the string numeric to each respective cell on column C, WHICH IS NOT, thus, I'm taking it out to have the value that I want in cell C1 to be 6
    Attached Files Attached Files
    Last edited by dluhut; 08-07-2014 at 04:54 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Sum of numeric String with Condition

    Perhaps
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sum of numeric String with Condition

    Quote Originally Posted by Pepe Le Mokko View Post
    Perhaps
    Please Login or Register  to view this content.
    I don't think your code actually takes into consideration that it's taking "Excel" in column B.

    Also, the column 'Desired Qty to Take' is not in my excel. It's just to show in this forum that, upon the condition that's met (it's Excel in column B, and take the Qty), that's what the quantity should be.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Sum of numeric String with Condition

    Assuming Quantity is always < 10
    =IF(AND(B2="Excel", ISERROR(Search("QTY", A2))), 1,IF(AND(B2="Excel", ISNUMBER(Search("qty", A2))),MID(A2, Search("qty", A2)-2,1)+0, 0))
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sum of numeric String with Condition

    Quote Originally Posted by ChemistB View Post
    Assuming Quantity is always < 10
    =IF(AND(B2="Excel", ISERROR(Search("QTY", A2))), 1,IF(AND(B2="Excel", ISNUMBER(Search("qty", A2))),MID(A2, Search("qty", A2)-2,1)+0, 0))
    Bad example on my part, but quantity could be in 3 digits (maximum)

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Sum of numeric String with Condition

    And will there ever be other digits/numbers in your text. I'm thinking maybe a UDF to extract the number.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Sum of numeric String with Condition

    May be this......
    Please Login or Register  to view this content.
    Is this what you are trying to achieve?
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  8. #8
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sum of numeric String with Condition

    First of all, thank you for all the help. But I'm trying to have the sum of the 'Qty' in column A with 'Excel' condition in column B in Cell C1.

  9. #9
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Sum of numeric String with Condition

    I'm stumped. Nothing I've tried works.

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    Hi,

    Have I missed something, or has an actual workbook yet to be uploaded as part of this thread? If not, sounds like it's badly needed.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  11. #11
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sum of numeric String with Condition

    Quote Originally Posted by XOR LX View Post
    Hi,

    Have I missed something, or has an actual workbook yet to be uploaded as part of this thread? If not, sounds like it's badly needed.

    Regards
    Sample attached...which is practically the same as what I've done in the 1st thread, but make it into a tabular form

  12. #12
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    Quote Originally Posted by dluhut View Post
    Sample attached...which is practically the same as what I've done in the 1st thread, but make it into a tabular form
    Can't see it (?)

    Regards

  13. #13
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Sum of numeric String with Condition

    It's attached to the first post.

    Hope this helps.

    Pete

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    Quote Originally Posted by Pete_UK View Post
    It's attached to the first post.

    Hope this helps.

    Pete
    Ah! Thanks, Pete.

    Regards

  15. #15
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    So if a quantity does exist in the string, it is always contained within parentheses at the very end of the string followed by a space and the word "Qty"?

    Regards

  16. #16
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum of numeric String with Condition

    well this works array entered
    =SUMPRODUCT((IF(ISNUMBER(--SUBSTITUTE(MID(A1:A5,SEARCH("(*)",A1:A5)+1,10)," Qty)","")),--SUBSTITUTE(MID(A1:A5,SEARCH("(*)",A1:A5)+1,10)," Qty)",""),1)),--(B1:B5="excel"))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  17. #17
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    Quote Originally Posted by martindwilson View Post
    well this works array entered
    =SUMPRODUCT((IF(ISNUMBER(--SUBSTITUTE(MID(A1:A5,SEARCH("(*)",A1:A5)+1,10)," Qty)","")),--SUBSTITUTE(MID(A1:A5,SEARCH("(*)",A1:A5)+1,10)," Qty)",""),1)),--(B1:B5="excel"))
    SUMPRODUCT in an array formula?! Ouch!

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of numeric String with Condition

    Try this array formula**:

    =SUM(IF(ISNUMBER(SEARCH("qty",A2:A6)),IF(B2:B6="Excel",--SUBSTITUTE(MID(A2:A6,FIND("(",A2:A6)+1,20)," Qty)",""))))+COUNTIFS(A2:A6,"<>",A2:A6,"<>*Qty*",B2:B6,"Excel")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  19. #19
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    Might as well put my two cents' worth in. Array formula**:

    =-SUM((B2:B6="Excel")*(IFERROR(0+TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(A2:A6,"Qty","")," ",REPT(" ",MAX(LEN(A2:A6)))),2*MAX(LEN(A2:A6)))),-1)))

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

  20. #20
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of numeric String with Condition

    Quote Originally Posted by martindwilson View Post
    well this works array entered
    =SUMPRODUCT((IF(ISNUMBER(--SUBSTITUTE(MID(A1:A5,SEARCH("(*)",A1:A5)+1,10)," Qty)","")),--SUBSTITUTE(MID(A1:A5,SEARCH("(*)",A1:A5)+1,10)," Qty)",""),1)),--(B1:B5="excel"))
    Empty cells could cause an incorrect result.

  21. #21
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum of numeric String with Condition

    yep a blank in col a gives 1 but it prompted you lot to get of your butts and have a go

  22. #22
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of numeric String with Condition

    Quote Originally Posted by XOR LX View Post
    =-SUM((B2:B6="Excel")*(IFERROR(0+TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(A2:A6,"Qty","")," ",REPT(" ",MAX(LEN(A2:A6)))),2*MAX(LEN(A2:A6)))),-1)))
    No empty cells in the sample data but if there were that formula could return an incorrect result.

  23. #23
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Sum of numeric String with Condition

    Quote Originally Posted by Tony Valko View Post
    No empty cells in the sample data but if there were that formula could return an incorrect result.
    True. Should've considered it as a possibility. Getting late here!

    Cheers

  24. #24
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Sum of numeric String with Condition

    =SUM(IF(B2:B6="Excel",IFERROR(SUBSTITUTE(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A2:A6," ",REPT(" ",255),LEN(A2:A6)-LEN(SUBSTITUTE(A2:A6," ",""))-1),255)),"(",""),"Qty)","")+0,1)))

    ...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.

    A
    B
    C
    1
    String with Quantity Headers Categories Desired Answer in Cell C2
    2
    some string name and ended with (4 Qty) PowerPoint
    16
    3
    some string name WITHOUT the word Qty Excel
    4
    some string name and ended with (12 Qty) Excel
    5
    some string name and ended with (3 Qty) Excel
    6
    some string name and ended with (5 Qty) Word
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  25. #25
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum of numeric String with Condition

    id assume a)that cell wont be empty
    but b) if it was it wouldn't have excel in col b
    and also assume that the string in a didn't contain any more () like
    "some string (this is ver 1) of my stuff (12 Qty)"
    so if the both mine and x or xls would fail with empty cells in col a
    x or xls works with additional () tho
    tony v works with empty cells but fails as so does mine with extra()
    lots of assumptions to be made on the raw data here

  26. #26
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of numeric String with Condition

    The thing about formulas...

    Almost any formula will fail if you try hard enough.

  27. #27
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sum of numeric String with Condition

    Quote Originally Posted by XOR LX View Post
    So if a quantity does exist in the string, it is always contained within parentheses at the very end of the string followed by a space and the word "Qty"?

    Regards
    Yes that's right

  28. #28
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum of numeric String with Condition

    you have had several suggestions already have you tried them? if so which work ,which don't?

+ 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] Need code to pull numeric data out of an alphanumeric string (string not constant)
    By harrydnyc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2013, 04:44 PM
  2. [SOLVED] Extract a mainly numeric string (ISSN number) from an arbitrary string
    By Buzzed Aldrin in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-04-2012, 01:49 PM
  3. Extracting Numeric Values from an Alpha/Numeric String
    By Delkath in forum Excel General
    Replies: 5
    Last Post: 10-27-2010, 02:36 PM
  4. Numeric value from a text string/numeric identifier?
    By lampshell in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-14-2008, 02:21 PM
  5. Replies: 3
    Last Post: 08-10-2006, 07:20 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