lundi 12 janvier 2015

VBA formula application-defined or object-defined error when inserting formula in VBA

I am trying to replace results with formulas, so the user would be able to see both values and formulas.



Sub MoreOrEqualAmountCalculated()

Dim LastRow As Long
Dim Counter As Long

With Application
.ScreenUpdating = False
End With

Application.Workbooks("Summary.xlsm").Worksheets("MonthlyData_Raw").Activate

LastRow = Range("A1000000").End(xlUp).Row

For Counter = 2 To LastRow
'Populate both results and FORMULA: There is an error 1004 - application-defined or object-'defined error. What am I missing?

Cells(Counter, 36).Formula = "=IF(Cells(Counter, 35).Value >= 0,""Recovery _
Equals or Exceeds Amount calculated"",""Recovery less than Amount _
calculated"")"

Next

With Application
.ScreenUpdating = True
End With

End Sub


I have seen a few related topics but none if them explained the rules around inserting formulas in details. I would appreciate your help and explicit explanation to be able to apply this knowledge in the future.


Thank you very much, Russ


Aucun commentaire:

Enregistrer un commentaire