Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why my calculated sum is different from VBA calculation 1

Status
Not open for further replies.

hirmo

Technical User
Apr 18, 2006
1
LU
Hi,
I'm trying to verify user calculated sums but with some figures VBA result does not mach XLS result even though the calculated result is correct. I made this simple code as an example:

Sub MySum()
Dim a As Double
Dim b As Double
Dim c As Double
Dim Result As Boolean


a = 622.685
b = 84.53
c = 707.215

Result = a + b = c
MsgBox a + b & " = " & c & " is " & Result


End Sub

More figures like that:
40.9 + 11.2 = 52.1
2447.1 + 3503.2 = 5950.3
52.1 + 303.6 = 355.7

Thanks a lot for your helpful comment!
 
Double are only approximations, so you may try this:
Result = (Abs(a + b - c) < 1E-12)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top