# help writing two If statements

##### Board Regular
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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

#### Norie

##### Well-known Member
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])"

##### Board Regular
Oh yea I should of thought of that.

Thank you

Replies
3
Views
227
Replies
5
Views
337
Replies
1
Views
244
Replies
3
Views
333
Replies
3
Views
131

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,163,487
Messages
5,831,982
Members
430,100
Latest member
namhnz

### 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.

### Which adblocker are you using?

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

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