activecell.formulaR1C1 引用 excel vba 中的另一个工作表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21005263/
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
activecell.formulaR1C1 referring to another sheet in excel vba
提问by dwstein
I'my trying to insert the following formula into the F column in a sheet using VBA:
我正在尝试使用 VBA 将以下公式插入到工作表中的 F 列中:
=VLOOKUP($C2,userOutput.csv!$A:$E2,4)
`user.Output.csv is another sheet in the same file. So, I've written the following bit of VBA code:
`user.Output.csv 是同一个文件中的另一个工作表。因此,我编写了以下 VBA 代码:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3], 'userOutput.csv'!R[2]C:R[162]C[5] ,4)"
But, the formula's that get inserted look as follows:
但是,插入的公式如下所示:
cell f2 has: =VLOOKUP(C2, userOutput.csv!F4:K164,4)
cell f3 has: =VLOOKUP(C3, userOutput.csv!F5:K165,4)
cell f4 has: =VLOOKUP(C4, userOutput.csv!F6:K166,4)
etc...
how to I get the correct formula with the dollar signs I need?
如何使用我需要的美元符号获得正确的公式?
回答by dwstein
Here's how I did it:
这是我如何做到的:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3], 'userOutput.csv'!R2C1:R162C5 ,4)"
Happy to hear alternatives!
很高兴听到替代方案!