简体   繁体   English

使用“= IF时运行时错误'1004'

[英]Run-time error '1004' when using "=IF

Adding the following formula to cell using VBA fails and I can't work out why: 使用VBA将以下公式添加到单元格失败,我无法解决原因:

"=IF($02,(IF(NOT($N2),$P1+1,1)),0)"

I can change the line to anything else eg "=A2/B2" and it runs fine. 我可以将线路改为其他任何东西,例如“= A2 / B2”,它运行正常。

Full code: 完整代码:

Sub FillDown() 

Dim strFormulas(1 To 2) As Variant 

With ThisWorkbook.Sheets("Sheet1") 
    LRow = .Range("A99999").End(xlUp).Row
    strFormulas(1) = "=IF($02,(IF(NOT($N2),$P1+1,1)),0)" 
    strFormulas(2) = "=A2/B2" 
   .Range("L2:T2").Formula = strFormulas
   .Range("L2:T" & LRow).FillDown 
End With 

End Sub 

Use this: 用这个:

 strFormulas(1) = "=IF($O2,(IF(NOT($N2),$P1+1,1)),0)" 

Instead of this: 而不是这个:

 strFormulas(1) = "=IF($02,(IF(NOT($N2),$P1+1,1)),0)" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM