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

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
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
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])"
 
Master Excel Bundle

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.

Forum statistics

Threads
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.
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
Top