[英]How do I apply a SumIf Formula in a VBA Sub? Getting Error 1004
I am trying to create a Sub that places a SUMIF
formula in a cell. 我正在尝试创建将
SUMIF
公式放在单元格中的Sub。 I have reduced the problem to a simple setup: 我已将问题简化为简单的设置:
Private Sub CommandButton1_Click()
Cells(2, 3).Formula = "=SUMIF(A1:A5;D1;B1:B5)"
End Sub
I get a 1004 Error
. 我收到
1004 Error
。
I can run the same code but with the SUM function instead: 我可以运行相同的代码,但可以使用SUM函数:
"=SUM(B1:B5)"
This does not produce an error. 这不会产生错误。 Thus I suspect the semicolons in my formula.
因此,我怀疑公式中的分号。
.Formula
accepts formulas in English. .Formula
接受英语公式。
Parameter separator in English is ,
. 在英语参数分隔符
,
。
If you want to use formulas in the language of your Excel installation, use .FormulaLocal
. 如果要使用Excel安装语言中的公式,请使用
.FormulaLocal
。
However to ensure your code will run on any Excel, fix your formula to be in accordance with the en-us
locale. 然而,为了确保您的代码将在任何Excel中运行,解决您的公式是按照
en-us
语言环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.