嵌套“和”语句与“或”语句

我的代码的这一行给我:错误13:types不匹配如何将“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 

提前致谢

将复合语句括在额外的括号中,以向编译器解释如何sorting逻辑语句…

尝试这个:

 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 

And条件是有点棘手,没有嵌套另一个Select CaseIf/Then在这个语句中,但假设你正在处理string或整数/长整型值,这应该工作(testing)。

 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 

如果你正在使用双精度/十进制数据types,那么我可能需要修改为(未经testing):

 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 Select