0

I use the follow code in Excel VBA:

If ((B - A) > 180) Then
    result = 1
ElseIf ((B - A) < -180) Then
    result = 2
Else
    result = 0
End If

In case (B - A) = 180, VBA returns result = 1. The debugger shows the first statement of the If as True even if (B - A) = 180

Is it VBA acting funny or more probably me missing something?

Any help will be much appreciated.

Community
  • 1
  • 1
eSimon
  • 1
  • 1
  • 5
    What is the variable type of B and A? If it's a Single or a Double (floating point type) then this may very well explain the odd behavior. [see here for decent explaination](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – JNevill Nov 03 '17 at 13:45
  • What are the values of `A` and `B`? – Vegard Nov 03 '17 at 13:59
  • `Range("A1").Value = B - A`, what do you see in cell A1? (keep out with the formatting) – Dominique Nov 03 '17 at 14:26
  • 1
    Possible duplicate of [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Blackwood Nov 03 '17 at 19:23

0 Answers0