Lorenzo
Lorenzo

Reputation: 25

Getting run-time error 1004 while trying to calculate using formula

I'm getting a run-time error while trying to calculate a common excel formula in VBA. Here's the part of the code that seems to have problems:

   With ActiveSheet
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   .Range("F4").Formula = "=IF(AND(C5=0;D5=0;E5=0);B5;IF(AND(C5=0;OR(D5<>0;E5<>0));B5;0))"
   .Range("F4").Copy
    With .Range("F5:F" & LastRow)
            .PasteSpecial Paste:=8
            .PasteSpecial Paste:=xlPasteFormulas
            .PasteSpecial Paste:=xlPasteFormats
    End With
End With

I'think there's simply something wrong in writing the formula using the correct VBA syntax, since if i just substitute with "=2+2" it works.

Upvotes: 1

Views: 99

Answers (1)

AnalystCave.com
AnalystCave.com

Reputation: 4984

Replace Semicolon with Comma

"=IF(AND(C5=0,D5=0,E5=0),B5,IF(AND(C5=0,OR(D5<>0,E5<>0)),B5,0))"

Upvotes: 1

Related Questions