Consulting

Results 1 to 9 of 9

Thread: Solved: Sum only Positive or Negative number

  1. #1

    Solved: Sum only Positive or Negative number

    Hi is it possible to sum either possible number or negative number in the given range using any formulae or thru VBA
    A mighty flame followeth a tiny sparkle!!



  2. #2
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Hi, for positive numbers try:

    =SUMIF(A1:A10,">0",A1:A10)*

    use <0 for negatives.

    *where your range is A1:A10
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =SUM(IF(rng>0,rng))

    =SUM(IF(rng<0,rng))

    which are array formulae, so commit with Ctrl-Shift-Enter

  4. #4
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Sorry to hijack your post excelliot, but XLD, is there an advantage to using SUM(IF over SUMIF( ? if so, what is it and when would SUMIF( be better?
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Babydum
    Sorry to hijack your post excelliot, but XLD, is there an advantage to using SUM(IF over SUMIF( ? if so, what is it and when would SUMIF( be better?
    No, yours is better as it is not an array formula. Dust in my eyes

  6. #6
    Hi Babydum,
    Could you explain the difference in these,
    as they give the same result?
    Which is better and why?

    '=SUMIF(A1:A10,">0")
    '=SUMIF(A1:A10,">0",A1:A10)
    Thx
    Quote Originally Posted by Babydum
    Hi, for positive numbers try:

    =SUMIF(A1:A10,">0",A1:A10)*

    use <0 for negatives.

    *where your range is A1:A10
    Dave
    "The game is afoot Watson"

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Desert Piranha
    Hi Babydum,
    Could you explain the difference in these,
    as they give the same result?
    Which is better and why?

    '=SUMIF(A1:A10,">0")
    '=SUMIF(A1:A10,">0",A1:A10)
    Thx
    SUMIF has two syntaxes, the first and most common is the SUMIF(rng1,value,rng2), which tests value against rng1, and sums the equivalent values in rng2 for matches. If rng2 is not specified, it means that the same range is used for for the test and the summing.

    I would suspect that the version with no specified summing range is quicker, but I need to get to my development machine to time it. I will post some results tomorrow.

  8. #8
    Hi xld,
    Thanks for the enlightenment.
    Thx again
    Dave
    Quote Originally Posted by xld
    SUMIF has two syntaxes, the first and most common is the SUMIF(rng1,value,rng2), which tests value against rng1, and sums the equivalent values in rng2 for matches. If rng2 is not specified, it means that the same range is used for for the test and the summing.

    I would suspect that the version with no specified summing range is quicker, but I need to get to my development machine to time it. I will post some results tomorrow.
    Dave
    "The game is afoot Watson"

  9. #9
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    A little extra... When I saw the first post, I thought "Ah, that's a SUMIF( thingy" But just to double check I typed a formula - like yours - into Excel, and I got the "the formula you typed contains an error" box. So I clicked the function icon to see that it was asking for two ranges.

    So, given your post, the chances are that the error was a typo - not a syntax one - but I just didn't stop to look...

    So now I understand better.

    Having said that, I don't do too many serious posts here, so I'm glad I did one that helped someone even if it was a tad too long.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •