View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Baffeling IF statement

On May 10, 4:31*pm, "wabbleknee" wrote:
I suspected that it was a rounding error, but dismissed it
because it was only happening with 0:50. *Surely, there has
to be others that are not an exact match


It will depend on the hours of the day in A1 and B1, referring to your
original posting. It is difficult to predict. It is not difficult to
write a macro to determine "all" pairs that cause problems. But even
that might vary, depending on if/how you extract(?) the time from a
date/time specification. I'm suspicious because of your MOD usage
below.

No matter. The point is: __always__ expect that the match will
__not__ be exact and program accordingly.

wabbleknee wrote:
from a pure number
As the original formula was implemented,

[....]
sometimes the hours run across the midnight hour.
i.e 23:59 to 0:10 . So my formula looks like this:
C7 time is when the clock starts, c8 thru c15 are
time elapse (goal measurements) from the starting
point. *=IF(C9="","",MOD(C9-$C$7,1)) then I am
checking the result against a maximum value
(<=goal) to see if we met that goal.


I must admit: it is unclear why you are using MOD and what
__exactly__ is in C7 and C9.

The best way to handle start/end times that might span across midnight
is to record date as well as time. You can also set the format to
display only time, if you wish. If you do this, elapsed time is
simply C9-C7 -- no need for MOD.

If you must record only time in C7 and C9, elapsed time is computed by
C9-C7+(C7C9) -- again, no need for MOD. Note that this assumes that
C7 and C9 are within 24 hours of each other.

In either case, I think TEXT is easier to use than ROUND in this
context. But I will demonstrate both.

=IF(C9="","",ROUND((C9-C7+(C7C9))*1440,0)/1440)

=IF(C9="","",--TEXT(C9-C7+(C7C9),"hh:mm"))

I would format using Custom [h]:mm as "good practice".

The [h] notation will display hours 24. But it appears you do not
expect that. So a Time option or Custom hh:mm might do just as well
for your purposes.

If that formula is in C10 and your goal is a constant in A1, you
should be able to write:

=IF(C10<=A1,"yes","no")

Alternatively, if your goal is 8 hours (e.g.), you could write any of
the following:

=IF(C10<=TIME(8,0,0),"yes","no")

=IF(C10<=--"08:00","yes","no")

The first form is preferred as "good practice".