LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
pod pod is offline
external usenet poster
 
Posts: 3
Default bad arithmetic

I have some VBA code within and Excel spreadsheet doing some simple
calculations, and then comparing the results. Although the numbers are
exactly the same, VBA thinks that they are different. Here is a
stripped-down version of the code.

First button to perform calculations:

Dim div_by_nine As Double

div_by_nine = Range("A1") / 9

Range("C1").Value = div_by_nine
Range("D1").Value = div_by_nine
Range("E1").Value = div_by_nine
Range("F1").Value = div_by_nine
Range("G1").Value = div_by_nine
Range("H1").Value = div_by_nine
Range("I1").Value = div_by_nine
Range("J1").Value = div_by_nine
Range("K1").Value = div_by_nine


Second button to compare results:

If Range("A1") < Range("A3") Then
MsgBox ("Values don't match")
Else
MsgBox ("Values match")
End If
MsgBox ("orig value = " & Range("A1") & "; calculated value = " &
Range("A3"))

Also, add the following formula in cell A3 on the spreadsheet:
=SUM(C1:K1)

To test, type in a value in cell A1, and then click on the first button to
spread the values, and then the second button to compare the results of A1
with A3. One number in particular that doesn't work is 12.825. (I know that
some other numbers don't work because of rounding, and I can get around
that,...but there is no rounding involved when using 12.825).

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date arithmetic Terry Pinnell Excel Discussion (Misc queries) 6 December 31st 08 02:53 PM
About arithmetic Formulas Ravindrapawanbindabinurajendradhamidevfa Excel Discussion (Misc queries) 2 August 13th 06 05:03 PM
Simple arithmetic Ron Rosenfeld Excel Discussion (Misc queries) 1 January 24th 05 08:35 PM
Simple arithmetic - take 2 Pat Excel Discussion (Misc queries) 1 January 24th 05 08:15 PM
formula arithmetic R Excel Programming 1 June 28th 04 03:52 PM


All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"