简体   繁体   English

Excel宏将公式添加到单元格不起作用

[英]Excel macro adding formula to cell not working

Aplogies for typos.. Having the write this on my phone due to restrictions at work. 打字错误的道歉。由于工作限制,请在我的手机上写这篇文章。 I've got a macro in excel that is as part of the application adding a formula to a cell 我在excel中有一个宏,它是在应用程序中向单元格添加公式的一部分

ActiveCell.FormulaR1C1 = "=IF(COUNTA([@[TABLECELL]])=0,"""",VLOOKUP([@[TABLECELL]],Sheet1!K:L,2,FALSE))"

The macro gets inserted but it's putting a bracket around the L. " Sheet!K:(L) " this means the formula doesn't work. 插入了宏,但是它在L周围放置了一个括号。“ Sheet!K:(L)”这意味着该公式无效。 Totally stumped why it's doing this. 完全不知道为什么要这么做。

So im not sure what you think by using [@[TABLECELL]], but take a look at this 因此,我不确定使用[@ [TABLECELL]]会怎么想,请看一下

ActiveCell.FormulaR1C1 = "=IF(COUNTA(R[-4]C[-1]:R[-4]C[2])=0,"""",VLOOKUP(R[1]C[-1]:R[2]C[2],Sheet1!C[5]:C[6],2,FALSE))"

When you are using formulaR1C1 you need to use proper cell adressing. 使用FormulaR1C1时,需要使用适当的单元格地址。 So feel free to change cell adreses in COUNTA and VLOOKUP to your tablecell and i think this should work 因此,随时将COUNTA和VLOOKUP中的单元格地址更改为您的表单元格,我认为这应该可行

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

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