1

这行代码给了我: 错误 13:类型不匹配 如何在“或”中组合“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

提前致谢

4

2 回答 2

0

将复合语句括在额外的括号中,以向编译器解释如何对逻辑语句进行排序...

试试这个:

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-17T20:25:13.757 回答
0

如果没有嵌套另一个或在此语句中,And条件有点棘手,但假设您正在处理字符串或整数/长值,这应该可以工作(经过测试)。Select CaseIf/Then

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 Select
于 2013-07-18T02:14:12.247 回答