VBA中用于IF语句的引号

时间:2018-08-29 12:56:11

标签: excel-vba double-quotes

我正在尝试复制某个范围内的IF公式,但是和其他问题一样,我的问题出在双引号上。我目前有CHR(34)表示我想要双引号,但是我的VBA错误是Expected end of line.

我需要它如何显示为公式:

=IF(D2=team,"",IF(D2=on," - Type1",IF(OR(D2=lr,D2=sn),"*"," - Type3")))

team, on, lr, sign是引用字符串的变量。

Range()= "=IF(D2=" & team & ", "&Chr(34)&Chr(34)&",IF(D2=" & on & ","&Chr(34)&" - Type1"&Chr(34)&",IF(OR(D2=" &lr& ",D2=" &sn& "),"&Chr(34)&"*"&Chr(34)&","&Chr(34)&" - Type3"& Chr(34)&")))"

它在D2语句的OR的第二个实例中显示错误

1 个答案:

答案 0 :(得分:0)

我相信以下代码应该可以正常工作,我只是将变量名从on更改为oni,因为我认为您不能拥有名为on的变量我也用空格分隔&:

ActiveCell.Formula = "=IF(D2=" & team & ", " & Chr(34) & Chr(34) & ",IF(D2="" & oni & ""," & Chr(34) & " - Type1" & Chr(34) & ",IF(OR(D2=" & lr & ",D2=" & sn & ")," & Chr(34) & "*" & Chr(34) & "," & Chr(34) & " - Type3" & Chr(34) & ")))"