Reputation: 89
I am trying to add an IF formula to a cell in excel using a macro and it is displaying a 1004 application-defined or object-defined error for the .Range line. How can I prevent this error?
Sub AddFormula()
Dim Formula As Variant
With ThisWorkbook.Worksheets("Form Responses 1")
.Range("CE2").Formula = "=IFERROR(IF(OR((BZ2=""No"", BZ2=""0"")), BZ2, AN2), AN2)"
End With
End Sub
Thanks
Upvotes: 0
Views: 461
Reputation: 2259
I think the issue is that the formula you supplied is not valid. There are too many brackets in the OR part.
try this instead
Sub AddFormula()
Dim Formula As Variant
With ThisWorkbook.Worksheets("Form Responses 1")
.Range("CE2").Formula = "=IFERROR(IF(OR(BZ2=""No"", BZ2=""0""), BZ2, AN2), AN2)"
End With
End Sub
Upvotes: 0