0
Sub Test()
    Dim iX As Integer

    iX = 1 = 1

    'Out put is -1
    MsgBox iX 
End Sub

1 Answer 1

4

Because if you compare 1 with a 1 this is True so 1 = 1 is True and True is considered as -1 in VBA by definition and you write this result into your variable iX.

This iX = 1 = 1 is evaluated the same as iX = (1 = 1) and this is iX = True and since iX is Integer the True is converted into a numeric value -1.

By definition in VBA:

  • True is -1
  • False is 0

But in Excel formulas

  • True is 1
  • False is 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.