Modify if statement & formula

abberyfarm

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

The code below calculates the efficiency of a gear box based on the values in previous cells and set parameters. It has two conditions at the moment, the first being if rc[-1] is 0 then return 0 and the second is ,if the value calculated is greater than 1 then return 1.

My question is how can I modify it to include if the value calculated is less than 0 then return zero.

Thank you

Code:
Range("AC2:AC" & Lastrow3).FormulaR1C1 = "=If(if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1])))>1,1,if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1]))))"
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try

Code:
Range("AC2:AC" & Lastrow3).FormulaR1C1 = "=If(if(rc[-1] = 0, 0, max(0,(rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1])))>1,1,if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1])))))"
 
Upvote 0
It works for me fine?, the two conditions included

I'll copy it again
Code:
Range("AC1").Value = "Gearbox efficiency"
    Range("AC2:AC" & Lastrow3).FormulaR1C1 = "=If(if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1])))>1,1,if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1]))))"
 
Upvote 0
Maybe (doesn't error but I have no idea if it gives a correct result)

Code:
Range("AC2:AC" & Lastrow3).FormulaR1C1 = "=max(0,If(if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1])))>1,1,if(rc[-1] = 0, 0, (rc[-2] * rc[-1])/ ((rc[-2] * rc[-1]) + (" & ksl & " * " & Gearratio & " * " & Gearratio & " * " & MaxTorque & " * rc[-1]) + (" & km & " + " & kb & ") * (rc[-2]*rc[-1])))))"
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
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