an if loop

abberyfarm

Well-known Member
Joined
Aug 14, 2011
Messages
733
Hi there,

I have a sum below and I need to create an if loop. How can I say, if the value calculated is less than zero and rc[-21] is greater than 2000, then return zero. Else return the sum (which will be positive).

Thank you

Code:
Range("z2:z" & Lastrow3).FormulaR1C1 = "=rc[-1] + rc[-2] + rc[-3] + rc[-11]"
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi there,

I have a sum below and I need to create an if loop. How can I say, if the value calculated is less than zero and rc[-21] is greater than 2000, then return zero. Else return the sum (which will be positive).

Thank you

Code:
Range("z2:z" & Lastrow3).FormulaR1C1 = "=rc[-1] + rc[-2] + rc[-3] + rc[-11]"
I'm a little confused.

1. I don't see what a loop has to do with it.

2. Why are we checking if column E > 2000 since you appear to be saying that W+X+Y will be positive if W+X+Y < 0 and E > 2000 is not true?

That is, is it possible that W+X+Y < 0 and E <= 2000? If so, what should be returned?
 
Last edited:
Upvote 0
I'm a little confused.

1. I don't see what a loop has to do with it.

2. Why are we checking if column E > 2000 since you appear to be saying that W+X+Y will be positive if W+X+Y < 0 and E > 2000 is not true?

That is, is it possible that W+X+Y < 0 and E <= 2000? If so, what should be returned?

Sorry I meant to say an if condition not a loop.

I want it to do, if O+W+X+Y < 0 and E > 2000 then return 0. If O+W+X+Y < 0 and E < 0 then return the value. If O+W+X+Y > 0 and E > 0 the return the value.

Hope that makes sense

Thanks
 
Upvote 0
What about O+W+X+Y < 0 and E between 0 and 2000?

What about O+W+X+Y > 0 and E <= 0?
 
Upvote 0
What about O+W+X+Y < 0 and E between 0 and 2000?

What about O+W+X+Y > 0 and E <= 0?

If O+W+X+Y < 0 and E between 0 and 2000 then return the summed value.

If O+W+X+Y > 0 and E <= 0, this would never happen in my case, but to satisfy the condition it should return the summed value also.

Thank you
 
Upvote 0
OK, try this as your FormulaR1C1

"=(RC[-11]+RC[-1]+RC[-2]+RC[-3])*OR(RC[-1]+RC[-2]+RC[-3]+RC[-11]>0,RC[-21]<=2000)"
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,835
Members
452,947
Latest member
Gerry_F

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