Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 使用VBA将公式指定给单元格?_Excel_Vba - Fatal编程技术网

Excel 使用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)/

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)/(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