I tried googling but without luck.

How do I add =ADD(E19,G19) but only if g19 is >0. If g19 is <0 then Minus?

  • 1
    Welcome to Web Applications Stack Exchange. Your question is a bit unclear: assuming that the two values are 10 and 5, you probably want the result to be 15. But what do you want the result to be with the two values are 10 and -5? Would it be 5 or 15? Nov 4 '21 at 15:53

To add the absolute value in cell G19, use the abs() function, like this:

=E19 + abs(G19)

To add the value in cell G19 when it is positive or zero, and subtract it when it is negative, use simple addition, like this:

=E19 + G19

  • The OP's use of the word "if" almost demands an equivalent response - and that might not be a bad thing. But =E19 + G19 is so deceptively simple that it should make one pause to consider one's assumptions... so what if "g19 is negative"?
    – Tedinoz
    Nov 5 '21 at 9:26
  • In OP's description, all that matters is the sign of G19. If the intention is to add or subtract depending on whether G19 is positive or negative, the plain vanilla + operator will handle both cases. If the intention is to always add the absolute value, the abs() function will handle both cases. Nov 5 '21 at 10:42
  • I agree completely. What I "meant" to say was that the OP (or anyone for that matter) may have been musing and the idea of "if" was how the relationship played out in their mind. Kind-of like... Maslow's hammer But IF is irrelevant for exactly the reasons you describe. Rather, =E19 + G19 should make one reflect on the underlying math - since regardless of the value of G19, the formula will be valid.
    – Tedinoz
    Nov 5 '21 at 10:50
  • Hi all thank you for helping. I actually replied yesterday but looks like it didn't upload the answer. =E19 + abs(G19) This code seems to work what i wanted. I had to calculate the total number of investment, so i wanted to add current value with profit, but if the profit was on the negative i wanted it to minus that from current value, which will give me total amount of investment. (Or other way around, but that code seems to work what I'm looking for!) -- Thank you all for helping!
    – Bn Minki
    Nov 5 '21 at 11:18

Question doesn't really make sense without knowing more about what you’re trying to do, but nonetheless:

=if(G19>=0, G19+E19, G19-E19)

  • 1
    I think the formula should be =if(G19>0,E19+G19,E19+G19), since the OP wants to have E19 as the first value in the formula, Let's say that E19=9 and G19=5, then G19 being greater than zero, the result should be 14. Yes? Now, suppose that G19 = -5. Your formula would become (-5-+9) and the result = -14. But another solution would be (9+-5), which equals 4. Precedence matters.
    – Tedinoz
    Nov 5 '21 at 11:06
  • @Tedinoz This is what I meant by the question not making sense. But your point is valid if that is OP's intention.
    – Kevin
    Nov 5 '21 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.