本文介绍了如何在VBA Sub中应用SumIf公式?出现错误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

我得到一个1004 Error.

我可以运行相同的代码,但可以使用SUM函数:

I can run the same code but with the SUM function instead:

"=SUM(B1:B5)"

这不会产生错误.因此,我怀疑公式中的分号.

This does not produce an error. Thus I suspect the semicolons in my formula.

推荐答案

.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 Sub中应用SumIf公式?出现错误1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 14:58