在 VBA 中插入公式时 VBA 公式应用程序定义或对象定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27905299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA formula application-defined or object-defined error when inserting formula in VBA
提问by LearnForever
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
非常感谢你,拉斯
回答by Maciej Los
Try this:
尝试这个:
Cells(Counter, 36).Formula = "=IF(" & Cells(Counter, 35).Address & " >= 0,""Recovery " & _
"Equals or Exceeds Amount calculated"",""Recovery less than Amount " & _
"calculated"")"