简体   繁体   English

Excel VBA中的VLOOKUP公式不起作用

[英]VLOOKUP formula in Excel VBA is not working

I am trying to make this formula work in VBA, but it keeps telling that "B2" is supposed to be the end of the statement. 我正在尝试使此公式在VBA中起作用,但始终告诉我们“ B2”应该是语句的结尾。 The code is provided below: 下面提供了代码:

With Range("J2:J" & LastRow)
    .Formula = "=I2/VLOOKUP(A2&"B2", MARM!A:G, 7, 0)"
    .Value = .Value
End With

If I want for the formula, when it is 0 or #N/A to leave the cell empty I used the code but it is not working.. Any ideas? 如果我想要公式,当它为0或#N / A时,将单元格留空时,我使用了代码,但是它不起作用。

.Formula = "=IF(VLOOKUP(A2&""B2"",MARM!A:G,7,0)=0,"""",VLOOKUP(A2&""B2"",MARM!A:G,7,0))"

Edit 编辑

With Range("J2:J" & LastRow)
.Formula = "=IF(IFERROR(I2/VLOOKUP(A2&""B2"",MARM!A:G,7,0),"""")=0,"""",IFERROR(I2/VLOOKUP(A2&""B2"",MARM!A:G,7,0),""""))"
.Value = .Value
End With

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

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