View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Fredrik Wahlgren Fredrik Wahlgren is offline
external usenet poster
 
Posts: 339
Default It doesn't add up - It's driving me crazy

It seems as if you only sum the values in cell A1.
For Each c In Range("A1").CurrentRegion.Cells


Shouldn't this line be rewritten as
For Each c In Range("A1:A5").CurrentRegion.Cells

/Fredrik


"Francis Hayes (The Excel Addict)"
wrote in message
...
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.

Thanks for your help.
Francis