使用If,Vlookup和Match语句,但收到“编译期望错误:语句结束”

在Excel电子表格中有多个选项卡的情况下,我一直在处理下面的代码。 它应该在另一个选项卡上执行一个Vlookup,其中一个表格显示了各种安全types和字段,分别是“是”或“否”。 根据字段,它将执行BDPfunction或返回“#N / A字段不适用”。

我尝试使用双引号,但仍然收到以下行后的错误

Cells(r, c)"=If(VLOOKUP(EQUITY, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=""Yes"", ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")"" 

我怎么能解决这个问题,或者我错过了任何引号?

下面的VBA:

 r = 2 While Cells(r, "A") <> "" c = 2 For c = 2 To 79 'Cells(r, c) = "=BDP(Cells(" & r & "," & c & "), Cells(1," & c & "))" If InStr(RC1, "EQUITY") <> 0 Then Cells(r, c)"=If(VLOOKUP(EQUITY, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=""Yes"", ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")" ElseIf InStr(RC1, "GOVT") <> 0 Then Cells(r, c)"=If(VLOOKUP(GOVT, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=Yes, ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")" ElseIf InStr(RC1, "CORP") <> 0 Then Cells(r, c)"=If(VLOOKUP(CORP, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=Yes, ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")" ElseIf InStr(RC1, "INDEX") <> 0 Then Cells(r, c)"=If(VLOOKUP(INDEX, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=Yes, ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")" ElseIf InStr(RC1, "COMDTY") <> 0 Then Cells(r, c)"=If(VLOOKUP(COMDTY, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=Yes, ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")" ElseIf InStr(RC1, "MTGE") <> 0 Then Cells(r, c)"=If(VLOOKUP(MTGE, 'Mandatory Field Control'!$A$1:$CA$7, MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=Yes, ""=BDP(RC1,R1C)"", ""#N/A Field Not Applicable"")" 

万一

  Next c r = r + 1 Wend 

你应该使用:

 Cells(r,c).Formula = "=Formula Here" 

编辑:你也必须缺less双引号Yes

 MATCH(B4,'Mandatory Field Control'!$B$1:$CA$1), FALSE)=Yes 

在所有的行,但第一个。 而且Jeeped提到你的Match函数应该更新为01 / -1 ,具体取决于你想要返回的结果。

作为一个个人喜好的问题,我也将使用Select Case而不是If Then为了便于阅读:

 Select Case True Case(RC1 Like "*EQUITY*") 'I assume RC1 is a variable Cells(r,c).Formula = "=Formula here" Case(RC1 Like "*GOVT*") Cells(r,c).Formula = "=Formula here" ... End Select