Gajju
Gajju

Reputation: 443

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. 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         

Upvotes: 1

Views: 124

Answers (2)

Shashidhara K
Shashidhara K

Reputation: 51

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. This is one of the possibility.

Upvotes: 1

z̫͋
z̫͋

Reputation: 1571

& is for string concatenation.

You are probably looking for the And operator to perform boolean operations.

Upvotes: 3

Related Questions