Excel VBA 运行时错误 1004 将公式插入或值到单元格中时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28557438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:15:45  来源:igfitidea点击:

Excel VBA Run-time error 1004 when inserting or value formula into cell

excelvbaexcel-vba

提问by kpp

I got the run-time 1004 error when It try to insert a formula into a cell

尝试将公式插入单元格时出现运行时 1004 错误

Range("B64").Value = "=INDEX(AK7:AK123;G74;1)"

//I also tried
Range("B64").Formula = "=INDEX(AK7:AK123;G74;1)"
//And
Range("B64").FormulaR1C1 = "=INDEX(AK7:AK123;G74;1)"

But this gives the error. If I try inserting a number or a regular string like "test"it does work, but like this it doesn't. Im new to VBA and im wondering why this would give a problem since it would never in languages im used to.

但这给出了错误。如果我尝试插入一个数字或一个常规字符串,就像"test"它确实有效,但像这样它没有。我是 VBA 新手,我想知道为什么这会产生问题,因为它永远不会出现在我习惯的语言中。

回答by

Inserting a formula with VBA requires that you use EN-US standards like,

使用 VBA 插入公式需要您使用 EN-US 标准,例如,

Range("B64").Formula = "=INDEX(AK7:AK123, G74, 1)"

... or use the regional formula attribute like,

...或使用区域公式属性,如,

Range("B64").FormulaLocal = "=INDEX(AK7:AK123; G74; 1)"

You may have to also change INDEXto the regional equivalent. The latter is necessary when you have a system with regional settings that do not use the EN-US standard of a comma for a list separator.

您可能还必须将INDEX更改为区域等效项。当您的系统具有不使用 EN-US 标准的逗号作为列表分隔符的区域设置时,后者是必需的。

see Range.FormulaLocal Property (Excel)for more information.

有关详细信息,请参阅Range.FormulaLocal 属性 (Excel)