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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
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])"
 

Watch MrExcel Video

Forum statistics

Threads
1,108,924
Messages
5,525,661
Members
409,658
Latest member
Yardcell

This Week's Hot Topics

Top