1

I am trying to figure out why for two variant variables that are identical, vba says it's not.

Excel screenshot - no particular formatting

Public netw, netw_c As Variant

netw = Range("C2").Value
netw_c = Range("C1").Value * Range("B2").Value

If netw <> netw_c Then
    StrUoM = StrUoM + "Error on net weight, net weight of CS is different to the net weight ZCU times their number in it." & Chr(10)
End If

Why this if loop returns me a true statement ? I noticed also, by looking a lot into this issue that if I declared my two variables netw, netw_c as Single. So, the problem is not about making it functionnal, it works with this declaration but, I don't understand why.

Here are how are defined the variable in VBA: local variable on VBA

Thank you !

Xela
  • 158
  • 9
  • 1
    Basically, you need to round your results to a specified decimal place before comparing. – jamheadart Oct 15 '20 at 10:43
  • 1
    You can't compare floating point numbers as they cannot be represented exactly in binary. The condition `0.1 + 0.1 + 0.1 = 0.3` returns false . – Kostas K. Oct 15 '20 at 10:53
  • Thank you guys. I am still troubled about this but I will admit it, ok :) – Xela Oct 15 '20 at 13:03

0 Answers0