简体   繁体   English

VBA代码显示“类型不匹配”错误

[英]VBA code shows “Type Mismatch” error

I have this VBA code that throws "type mismatch" error, its the second if statement that is throwing the error.I think its the comparison operators that are creating the problem but don't know how to fix it. 我有引发“类型不匹配”错误的VBA代码,它是引发错误的第二个if语句。我认为它是造成问题但不知道如何解决的比较运算符。 Some help please 请帮忙

  If var1 = "IT" 
    If (var2 = "a") & (var3 >= 30) & (var3 <= 300) & (var4 <= 96) & (var5 <= 1) Then
        MsgBox "Compatible system is machine 1"
    End if
  End If         

& is for string concatenation. &用于字符串连接。

You are probably looking for the And operator to perform boolean operations. 您可能正在寻找And运算符来执行布尔运算。

It might the variables might be having the numbers in the form of text and it is comaparing the text with numbers like . 它可能使变量具有文本形式的数字,并且使文本与数字相匹配。 Consider Var3 = "30" (Number 30 but is text) and it is comparing "30" > = 30 which is a mismatch. 考虑Var3 =“ 30”(数字30,但为文本),它正在比较“ 30”> = 30,这是不匹配的。 This is one of the possibility. 这是可能性之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM