在VBA中插入公式时VBA公式应用程序定义或对象定义的错误

时间:2015-01-12 15:22:59

标签: excel vba excel-vba if-statement formula

我正在尝试用公式替换结果,因此用户可以看到值和公式。

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

我已经看过一些相关的主题,但如果他们解释了有关在细节中插入公式的规则,则没有。我将非常感谢您的帮助和明确的解释,以便将来能够应用这些知识。

非常感谢, 拉斯

1 个答案:

答案 0 :(得分:1)

试试这个:

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