Formula set in macro is not evaluated correctly

Macro:
nSheet.getCellByPosition(4, r ).Formula = “=SOM.ALS(Totalen.$B$1:Totalen.$B$567;D” + (r + 1) + “;Totalen.$A$1:Totalen.$A$567)”

If I set the formula above in my macro then the cell displays “#NAAM?” (Dutch Language, probably “#NAME?” in english I think)

But when I go to the cell and edit it without changing the formula then it executes it correctly. What do I do wrong? I also tried .setFormula.

setFormula only takes language-neutral standard syntax. Don’t use localized names (or other parts, like argument separators, decimal separators) with it. There is FormulaLocal property, but using it is also bad - your code wouldn’t work anywhere except in the same configuration.

May be so?

nSheet.getCellByPosition(4, r ).setFormula("=SUMIF(Totalen.$B$1:Totalen.$B$567;D" + (r + 1) + ";Totalen.$A$1:Totalen.$A$567)")

You can use FormulaLocal, but, in macros is better use only Formula and use the formulas name always in English.