简体   繁体   English

单元格(..)上的VBA运行时错误1004。公式

[英]VBA Runtime error 1004 on Cells(..).Formula

I can't make this simple command work: 我不能让这个简单的命令工作:

Cells(l, 7).Formula = "=" & var1 & " * " & var2 & " * " & var3 & " / 252"

I can paste the inspected formula string value in Excel and it works as expected. 我可以在Excel中粘贴检查的公式字符串值,它按预期工作。

Cells(l,7) is a proper reference, as I can inspect its value. 单元格(1,7)是一个合适的参考,因为我可以检查它的值。

Inspected formula on debug: "=86710597,9409 * 0,02 * 0,35 / 252" 调试时检查公式:“= 86710597,9409 * 0,02 * 0,35 / 252”

The problem is when a variable is represented as string it will have the system's decimal point. 问题是当变量表示为字符串时,它将具有系统的小数点。 In your case it is a comma so you need to convert it to dot, for example using replace() function. 在你的情况下它是一个逗号,所以你需要将它转换为点,例如使用replace()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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