Excel 使用VBA将公式指定给单元格?
VBA给了我一个错误Excel 使用VBA将公式指定给单元格?,excel,vba,Excel,Vba,VBA给了我一个错误1004: Sub UpdateCellsFormula() Dim FormulaRange As Range Dim i As Integer Set FormulaCellsRange = Range("J17", "J95") i = 17 For Each r In FormulaCellsRange.Cells r.Formula = Replace("=D17*L21+E17*M21+F17*O21+G17*N21+H17*P21+I17*Q21)/
1004
:
Sub UpdateCellsFormula()
Dim FormulaRange As Range
Dim i As Integer
Set FormulaCellsRange = Range("J17", "J95")
i = 17
For Each r In FormulaCellsRange.Cells
r.Formula = Replace("=D17*L21+E17*M21+F17*O21+G17*N21+H17*P21+I17*Q21)/(1+0,85+0,6+0,4+0,37)", "17", i)
i = i + 1
Next
End Sub
有人可以看一下吗?分配了
的公式。公式必须在En US地区。因此,数字中的小数点必须是
,而不是,
(1+0.85+0.6+0.4+0.37
)
另外,在开头,在=
之后缺少一个左括号
您可能还想了解Excel中的绝对引用。这样,您就可以将相同的公式复制到FormulaCellsRange
中的所有单元格中,而无需替换任何内容:
Sub UpdateCellsFormula()
ActiveSheet.Range("J17", "J95").Formula = "=(D17*$L$21+E17*$M$21+F17*$O$21+G17*$N$21+H17*$P$21+I17*$Q$21)/(1+0.85+0.6+0.4+0.37)"
End Sub