Excel VBA - 公式R1C1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15859166/
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-11 20:27:54  来源:igfitidea点击:

Excel VBA - FormulaR1C1

excelexcel-vbaexcel-formulavba

提问by Tejas

I am following formula using VBA Code,

我正在使用 VBA 代码遵循公式,

.Range("M2:M" & LastRow).FormulaR1C1 = "=vlookup(RC2 & RC3 & RC6 & RC7,trip_length!A:F,6,False)"

But when I see the formula by pressing F2, it shows as below:

但是当我按F2看到公式时,它显示如下:

=VLOOKUP($B2 & $C2 & $F2 & $G2,trip_length!A:(F),6,FALSE)

It's all correct EXCEPT the brackets around F. And because of that, formula returns an Error.

除了 F 周围的括号外,一切都是正确的。因此,公式返回错误。

I tried a lot but not able to figure out how to use static range (of another sheet) with FormulaR1C1.

我尝试了很多,但无法弄清楚如何在 FormulaR1C1 中使用静态范围(另一张纸的)。

Please help. Thanks.

请帮忙。谢谢。

采纳答案by chris neilsen

When using .FormulaR1C1, all range references must be in R1C1format. Therefore, use:

使用 时.FormulaR1C1,所有范围引用都必须采用R1C1格式。因此,使用:

.Range("M2:M" & LastRow).FormulaR1C1 = _
  "=vlookup(RC2 & RC3 & RC6 & RC7,trip_length!C1:C6,6,False)"