Formula only if numbers are positive.

PostTIT

Board Regular
Joined
Aug 22, 2016
Messages
94
I have a sheet that I'm using to keep track of a few things, not complicated but there's one formula I would like help with to tidy it up. the three websites at the top of my google search yielded nothing so I've come for help because evidently I'm lazy...

To make it really simple I'll only give one set of cells this applies to and then I can apply it to the rest.

Cell A3
has the following formula:

Code:
[B]=(A1*B1)+(A2*B2)[/B]

However A1 and A2 are dependant on another formula from other cells (which shouldn't be relevant to my problem). As a result, A1 and A2 could be either negative or positive.

Is there a way to make the given formula in A3 apply only if the value in A1 and A2 is positive? Some sort of IF statement maybe?

Next step would then be to have the formula work for only the positive number, by assuming the negative number is zero (without changing the actual value in the cell - any help on that would be great too.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Cell A3 [/B]has the following formula:

Code:
[B]=(A1*B1)+(A2*B2)[/B]

However A1 and A2 are dependant on another formula from other cells (which shouldn't be relevant to my problem). As a result, A1 and A2 could be either negative or positive.

Is there a way to make the given formula in A3 apply only if the value in A1 and A2 is positive? Some sort of IF statement maybe?
I assume by the highlighted text that you mean both A1 and A2 must be positive at the same time.

=IF(AND(A1>0,A2>0),A1*B1+A2*B2,"")

You did not say what should be displayed if either A1 or A2 (or both) are negative, so I chose to display the empty text string ("").



Next step would then be to have the formula work for only the positive number, by assuming the negative number is zero (without changing the actual value in the cell - any help on that would be great too.
This should do it...

=MAX(0,A1)*B1+MAX(0,A2)*B2
 
Last edited:
Upvote 0
Yeah that formula works a treat, thanks both.

Just out of interest I found a solution to my second question, and to more cells - found it by the magic of thinking for once... With this formula (If you can get your head around the shifted cells)

=IF(B2 < 0, (B3*C3)+(B4*C4)+(B5*C5), IF( B3 < 0, (B2*C2)+(B4*C4)+(B5*C5),IF(B4 < 0, (B2*C2)+(B3*C3)+(B5*C5),IF(B5 < 0, (B2*C2)+(B3*C3)+(B4*C4),(B2*C2)+(B3*C3)+(B4*C4)+(B5*C5)))))

and it could go on i suppose.
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top