View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gee Gee is offline
external usenet poster
 
Posts: 32
Default IF just STOPS WORKING

OK, all that said and my subsequent confusion, I never had a problem with
this kind of thing in '03, only in '07 and I'm still working on another
problem with it but the 13 decimal places solved the Yes/No problem just fine.
Thanks so much for your help.

If you know anything about Excel VBA Programming, I'm having another problem
with this project...It's under Excel Programming and the topic is "Sending 3
email?". You guys are good...I'd appreciate if you could give me some input
on this very last hurdle.
:)

"JoeU2004" wrote:

PS....


I wrote:
"David Biddulph" <groups [at] biddulph.org.uk wrote:
or to
=if(and(HI2=400.5,HI2<402.5), "YES", "NO")

[....]
People should learn not to compare with numbers with
decimal fractions, since most decimal fractions are
not exact internally. They will inevitably get a
surprising result.


But using ROUND in comparisons with numbers with decimal fractions is okay,
when done correctly. For example:

=if(and(400.5<=round(HI2,1),round(HI2,1)<402.5), "YES", "NO")

This is okay because ROUND ensures that the internal binary representation
of its result exactly matches a constant with the same number of decimal
places. For example, if A1 is =10.1-10, =(A1=0.1) returns FALSE, but
=(round(A1,1)=0.1) returns TRUE. The reason is: the binary representation
of 10.1-10 is not close enough to the binary representation of the constant
0.1 for Excel to consider them equal.

In contrast, if A1 is =0.1+2^-56, =(A1=0.1) returns TRUE even though the
binary representations of A1 and 0.1 are not the same. Likewise, =A1-0.1
returns zero. But =(A1-0.1) returns non-zero, namely about 1.39E-17. And
=IF(A1-0.1=0,TRUE) returns FALSE, which flies in the face of reason
considering the result of =A1-0.1, until we understand Excel's dubious
heuristic for determining "close enough".

But I digress....


----- original message -----

"JoeU2004" wrote in message
...
"David Biddulph" <groups [at] biddulph.org.uk wrote:
=if(and(401<=round(HI2,0),round(HI2,0)<=402), "YES", "NO")
would presumably be equivalent to
=if(or(round(HI2,0)=401,round(HI2,0)=402), "YES", "NO")


Yes, I thought of that, too. I chose not to mention it because I did not
want to confuse Gee anymore that he/she already seems to be. I chose the
more-general numeric range test because I wondered if integer limits are
really what Gee wants/needs.


or to
=if(and(HI2=400.5,HI2<402.5), "YES", "NO")


I disagree, especially considering Gee's continued confusion between
displayed and actual values. Depending on formatting, a cell might
display as 400.5 (expect "YES"), but it is actually 400.49 (resulting in
"NO").

People should learn not to compare with numbers with decimal fractions,
since most decimal fractions are not exact internally. They will
inevitably get a surprising result.


----- original message -----

"David Biddulph" <groups [at] biddulph.org.uk wrote in message
...
=if(and(401<=round(HI2,0),round(HI2,0)<=402), "YES", "NO") would
presumably be equivalent to
=if(or(round(HI2,0)=401,round(HI2,0)=402), "YES", "NO") or to
=if(and(HI2=400.5,HI2<402.5), "YES", "NO")
if either of those helps the OP to see whether that's what he wants.

[I have changed your H12s to the OP's HI2 reference.]
--
David Biddulph

"JoeU2004" wrote in message
...
"Gee" wrote:
I thought it might be something like that. I changed the columns
to no decimal places, but since it was getting data from an external
database it might have caused the problem.
It's working right now...if it stops I'll be back!

I think you missed the point. Changing the format only changes the
appearance of the cell value; it does not change the actual value.
WYSI(not)WYG!


You wrote previously:
=IF(AND(HI2401,HI2<402),"YES","NO")

If you are happy with displaying H12 with zero decimal places, it is no
longer clear what your intent is with the AND() expression above.

I suspect you want:

=if(and(401<=round(H12,0),round(H12,0)<=402), "YES", "NO")


----- original message -----

"Gee" wrote in message
...
I thought it might be something like that. I changed the columns to no
decimal places, but since it was getting data from an external database
it
might have caused the problem.
It's working right now...if it stops I'll be back!
Thank you SO much for the help! I was really in a corner.


"JoeU2004" wrote:

"Gee" wrote:
Why has this worked for about 3 hours and then suddenly stopped??

Define "working".


=IF(AND(HI2401,HI2<402),"YES","NO")

It probably has nothing to do with time of day, unless the value in
H12 is
derived from time of day (i.e. NOW()).

More likely, the value in H12 is not what it appears to be. For
example, if
the value is 401.00001, it might be displayed as 401, so you might
expect
"NO". But AND(401<H12,H12<402) returns TRUE, so you actual get "YES".

If that is not enough to help you, post again with details, namely the
formula and value in H12, formatted to 13 decimal places.


----- original message -----

"Gee" wrote in message
...
Why has this worked for about 3 hours and then suddenly stopped??

Excel 2007 is what I'm using

=IF(AND(HI2401,HI2<402),"YES","NO")

Thank you in advance for any help you can give me.