IF 语句的 VBA 内的引号
Qutation Marks within VBA for IF statement
我正在尝试复制一个范围内的 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)&")))"
它在 OR
语句
中的 D2
的第二个实例中显示错误
我相信下面的代码应该会如您所愿,我只是将变量名从 on
更改为 oni
,因为我认为您不能使用名为 [=11 的变量=]我还用空格分隔了&:
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) & ")))"
我正在尝试复制一个范围内的 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)&")))"
它在 OR
语句
D2
的第二个实例中显示错误
我相信下面的代码应该会如您所愿,我只是将变量名从 on
更改为 oni
,因为我认为您不能使用名为 [=11 的变量=]我还用空格分隔了&:
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) & ")))"