help writing two If statements

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi there,

I have an If statement below that works fine.

Code:
Do
    
    If ActiveCell.Offset(0, -15) = ActiveCell.Offset(-1, -15) Or ActiveCell.Offset(0, -12) > 0 Then
    ActiveCell.FormulaR1C1 = "=(rc[-3] / " & Gearratio & ") / rc[-1]"
    
    Else
    
    ActiveCell.FormulaR1C1 = "=(rc[-3] / " & Gearratio & ") * rc[-1]"
    
    End If

    ActiveCell.Offset(1, 0).Select

    Loop Until IsEmpty(ActiveCell(1, -1))

However, in the first part of the statement when the previous column is zero, it returns the #DIV/0! error.
Code:
ActiveCell.FormulaR1C1 = "=(rc[-3] / " & Gearratio & ") / rc[-1]

How can I put an If statement before this one, thats says If rc[-1] equals 0 then return 0 in this column, else do the above If loop.

Hope that makes sense.

Thank you
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Why not add the IF to the formula rather than the code?

"=IF(rc[-3] = 0, 0, (rc[-3] / " & Gearratio & ") * rc[-1])"

"=IF(rc[-3] = 0, 0, (rc[-3] / " & Gearratio & ") / rc[-1])"
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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