将此公式添加到单元格

时间:2014-01-24 11:17:53

标签: excel-vba vba excel

我不知道为什么不使用下面的代码,它给了我一个错误。

Sub addformula()
For i = 10 To 99
    For j = 10 To 99
    Sheet8.Cells(93 + i - 10, 20 + j - 10).Formula = "=IF(OR(AND(J" & i & " = 1; K" & j &  " = 1);AND(J" & j & " = 1; K" & i & " = 1));1;0)"
    Next
Next
End Sub

1 个答案:

答案 0 :(得分:0)

尝试使用逗号,代替分号;(即使您使用逗号作为标准分隔符):

Sub addformula()
    For i = 10 To 99
       For j = 10 To 99
          Sheet8.Cells(93 + i - 10, 20 + j - 10).Formula = "=IF(OR(AND(J" & i & " = 1, K" & j &  " = 1),AND(J" & j & " = 1, K" & i & " = 1)),1,0)"
       Next
    Next
End Sub