View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Type Mismatch error when number is negative

Yes you can compare to negative number. But I suspect the type mismatch is
in the assignment of the value to var1;
- When countA - countB is positive a number is returned
- When countA - countB is negative, a non-integer value is returned

Private Sub CommandButton1_Click()
Dim var1 As Integer
var1 = -2
Debug.Print var1
If var1 0 Then
MsgBox "Positive"
Else
MsgBox "Negative"
End If

End Sub

NickHK

"D.Farns" wrote in message
...
Hello,

Need a little VBA help.

dim var1 as integer
var1 = countA - countB (for example)
If var1 0 then

This if statement works fine when var1 is a possitive number. When var1

is
a negative number I get a "Type Mismatch" error. Should I not be able to
compare a negative value with another number? I've tried declaring 0 as
integer variable to ensure both variables being compared in the If

statement
are of the same type, but that didn't help. Any suggestions?

--
D.Farns