VBA设置公式 - 获取错误1004 [英] VBA Set formula - getting Error 1004
问题描述
我正在尝试创建一个将SUMIF公式放在单元格中的Sub。我已经将问题减少到一个简单的设置:
I am trying to create a Sub that places a SUMIF formula in a cell. 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
电子表格的图片(我不能发布图片): http://i.imgur.com /qVSoDkv.png
Picture of the spreadsheet (I am not allowed to post pic's): http://i.imgur.com/qVSoDkv.png
运行代码时,我不断收到1004错误。
我可以运行相同的代码,但使用SUM函数:
I keep getting a 1004 Error when running the code. I can run the same code but with the SUM function instead:
"=SUM(B1:B5)"
这不会产生任何错误。因此,我怀疑分号,但无法提出解决方案。
This does not produce any errors. Thus I am suspecting the semicolons but have been unable to come up with a solution.
推荐答案
.Formula
接受英文中的公式。
英文参数分隔符为,
。
.Formula
accepts formulas in English.
Parameter separator in English is ,
.
如果要使用Excel安装语言中的公式,请使用 .FormulaLocal
。
If you want to use formulas in the language of your Excel installation, use .FormulaLocal
.
但是要确保您的代码可以在任何Excel中运行,请修改您的公式以符合 en-us
语言环境。
However to ensure your code will run on any Excel, fix your formula to be in accordance with the en-us
locale.
这篇关于VBA设置公式 - 获取错误1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!