VBA 在 VBA 中插入公式时公式应用程序定义或对象定义错误
VBA formula application-defined or object-defined error when inserting formula in VBA
我正在尝试用公式替换结果,以便用户能够同时看到值和公式。
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
我看过一些相关主题,但是 none 如果他们详细解释了有关插入公式的规则。感谢您的帮助和明确的解释,以便将来能够应用这些知识。
非常感谢,
拉斯
试试这个:
Cells(Counter, 36).Formula = "=IF(" & Cells(Counter, 35).Address & " >= 0,""Recovery " & _
"Equals or Exceeds Amount calculated"",""Recovery less than Amount " & _
"calculated"")"
我正在尝试用公式替换结果,以便用户能够同时看到值和公式。
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
我看过一些相关主题,但是 none 如果他们详细解释了有关插入公式的规则。感谢您的帮助和明确的解释,以便将来能够应用这些知识。
非常感谢, 拉斯
试试这个:
Cells(Counter, 36).Formula = "=IF(" & Cells(Counter, 35).Address & " >= 0,""Recovery " & _
"Equals or Exceeds Amount calculated"",""Recovery less than Amount " & _
"calculated"")"