下面这行代码告诉我:错误13:类型不匹配如何在"or“中组合"nd”语句?例如:如果a或b或c或(d和e)或(f和g)
以下是代码
If (cell.Value) = "FTV1" _
Or (cell.Value) = "FTV2" _
Or (cell.Value) = "FTV3" _
Or (cell.Value) = "FTV4" _
Or (cell.Value) = "FTV5" _
Or (cell.Value) = "ISTCR" _
Or (cell.Value) = "CAST" _
Or (cell.Value) = "Rig" _
Or (cell.Value) > 50000 And (cell.Value) < 52000 _
Or (cell.Value) > 55000 And (cell.Value) < 56000 Then提前感谢
发布于 2013-07-18 04:25:14
将复合语句括在额外的括号中,以向编译器解释如何对逻辑语句进行排序...
试试这个:
If (cell.Value) = "FTV1" _
Or (cell.Value) = "FTV2" _
Or (cell.Value) = "FTV3" _
Or (cell.Value) = "FTV4" _
Or (cell.Value) = "FTV5" _
Or (cell.Value) = "ISTCR" _
Or (cell.Value) = "CAST" _
Or (cell.Value) = "Rig" _
Or ((cell.Value) > 50000 And (cell.Value) < 52000) _
Or ((cell.Value) > 55000 And (cell.Value) < 56000) Then发布于 2013-07-18 10:14:12
如果不在这条语句中嵌套另一个Select Case或If/Then,And条件就有点棘手,但假设您正在处理字符串或整数/长值,这应该是有效的(经过测试)。
Select Case cell.Value
Case "FTV2", "FTV3", "FTV4", "FTV5", _
"ISTCR", "CAST", "Rig", _
50001 To 51999, 55001 To 55999
'Do your code or call subroutine/function, here.
Case Else
'Do other code, or, do nothing, if the above criteria not met.
End Select如果您正在使用双精度/十进制数据类型,那么我可能需要修改为(未测试):
Select Case cell.Value
Case "FTV2", "FTV3", "FTV4", "FTV5", _
"ISTCR", "CAST", "Rig", _
50000 to 56000
If (Not IsNumeric(cell.Value)) Or _
(50000 < cell.Value < 52000) Or _
(55000 < cell.Value < 56000) Then
'Do your code or call subroutine/function, here.
End If
Case Else
'Do other code, or, do nothing, if the above criteria not met.
End Selecthttps://stackoverflow.com/questions/17709309
复制相似问题