简体   繁体   中英

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. 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/qVSoDkvm.png]

I get a 1004 Error .

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 accepts formulas in English.
Parameter separator in English is , .

If you want to use formulas in the language of your Excel installation, use .FormulaLocal .

However to ensure your code will run on any Excel, fix your formula to be in accordance with the en-us locale.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM