1
votes

I'm always getting this error when inserting a formula with VBA in Excel 2013:

Run-time error '1004': Application-defined or object-defined error

This is my code:

strFormula = "=(K19 * P13) + (I19 * P13/3,2)"
strCelda = "M20"
Range(strCelda).Formula = strFormula <---- Error

I have tried with these values:

"=(K19 * P13) + (I19 * P13/3.2)"
"=(K19 * P13) + I19 * (P13/3.2)"

with no luck. Whatever the value I enter, I'm still getting the same error.

1
Sack that for a game of conkers! Have you tried debugging your code? - SierraOscar
This works just fine: Range(strCelda).formula = "=(K19 * P13) + (I19 * P13/3.2)" - Excel Hero
@MacroMan There was no need to delete you answer, editing would have been sufficient! - SQL Police
@SQLPolice I know but there was too much "noise" going on which starts to deviate form the post. It wouldn't have helped anyway so no harm done :) - SierraOscar
As you have stated in your OP, you have tried the answers that so many have given, my guess is there is something else that could be the problem, for example the sheet is protected or the sheet is not qualified properly. Could you post more of your code? - Scott Craner

1 Answers

2
votes

This works:

strFormula = "=(K19*P13)+(I19*P13/3.2)"

Replace comma by dot. In VBA, you always need to use the dot, regardless of your regional settings.