Posted to microsoft.public.excel.programming
|
|
It doesn't add up - It's driving me crazy
Check out
http://cpearson.com/excel/rounding.htm
In article ,
"Francis Hayes (The Excel Addict)"
wrote:
Sorry about that previous post. I was typing away and before I was finished
my post disappeared.
Here's the complete post...
-------------------------------------------
I need someone to tell me I'm not going crazy.
Please try this.
Enter the following data into a blank worksheet.
A1=.2
A2=.2
A3=.2
A4=.2
A5=.2
Notice that it adds up to 1 (i.e. 100%)
Copy this macro (below) into the workbook and run it.
Sub DoesntAddUp()
For Each c In Range("A1").CurrentRegion.Cells
amt = amt + c
Next c
If amt < 1 Then
MsgBox "Sorry, your total is < 1. Your total is = " & amt
Else
MsgBox "Congratulations. Your total is " & amt
End If
End Sub
You should get a message saying 'Congratulations. Your total is =1'
Now, change A1 to .3 and A5 to .1
Now run the macro again.
Did you get a message saying 'Sorry, your total is < 1. Your total is = 1'?
Step through the macro and notice on the line 'If amt < 1 Then' that the
variable amt = 1 but this still evaluates to TRUE.
Can someone explain to me what's happening? I've tried this on several
computers, each time with the same result.
|