Home » excel » excel – Whats wrong with one statement(Error 1004)

excel – Whats wrong with one statement(Error 1004)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have this statement:

.Cells(14, 22).Value = "=(" & dblSafety & "+V76*AP28)" & "/AP46"

dblSafety has double as type and the value: 10779717,8414514

It writes a Formula in a Cell. The Formula should look like this:

=(10779717,8414514 + V76 * AP28) / AP46

But i get the Error with the Number 1004. I have the german version so it says:

“Anwendungs- oder Objektdefinierter Fehler”

I think in english it would be:

“Application-defined or Object-defined error”

I dont understand why there is an error. If dblSafety is 0 then there is no error. Is the Number to big?

Any Help is appreciated

edit
If I convert the variable to a long type I dont get any errors, but I need the decimal part.

How to&Answers:

You need to substitute explicitly the comma , with a decimal point . before concatenating to your formula.

Excel and VBA are not as locale-friendly as they ought to be: the implicit CStr is causing the problem.