Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
sudeep
 
Posts: n/a
Default About nesting the hour function

I have an worksheet with cell C9=8:30 and D9=17.30 . Then in another cell i
compute the number of hours above 9 that i have been working by
=HOUR((D9-C9)-TIME(9,0,0)). For the above combination i get an error #NUM!.
If i do the same in 2 steps say D10=(D9-C9)-(TIME(9,0,0)) and D11=HOUR(D10)
evrything is fine. Can you tell me why and if there is any way to avoid it?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld
 
Posts: n/a
Default About nesting the hour function

On Tue, 24 Jan 2006 06:52:04 -0800, sudeep
wrote:

I have an worksheet with cell C9=8:30 and D9=17.30 . Then in another cell i
compute the number of hours above 9 that i have been working by
=HOUR((D9-C9)-TIME(9,0,0)). For the above combination i get an error #NUM!.
If i do the same in 2 steps say D10=(D9-C9)-(TIME(9,0,0)) and D11=HOUR(D10)
evrything is fine. Can you tell me why and if there is any way to avoid it?



It's a rounding error due to the manner in which Excel (and other SS's) handle
the IEEE double precision specifications.

If, in D10, instead of entering:

=(D9-C9)-(TIME(9,0,0))

you were to enclose that in parentheses:

=((D9-C9)-(TIME(9,0,0)))

as you would before adding the HOUR function, you would see the same error as
that calculation is returning: -5.5511151231257800E-17

The HOUR function then returns an error since the value it is looking at is
negative.

You can work around it by ROUNDing your result.

=HOUR(ROUND(D9-C9-TIME(9,0,0),5))

But there's no real need to use the HOUR function. As a matter of fact, you
can probably eliminate both the HOUR and ROUND functions, and also not have to
worry about the fact that the HOUR function will only return numbers 0-23 by
using:

=24*(D9-C9-TIME(9,0,0))

or, if you must have an integer result:

=TRUNC(24*(D9-C9-TIME(9,0,0)))

The TRUNC function will give a zero for the very small negative numbers that an
apparent equality sometimes returns.
--ron
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Sloth
 
Posts: n/a
Default About nesting the hour function

=INT((D9-C9)*24)-9
or
=HOUR(24+D9-C9-TIME(9,0,0))

Try these formulas instead. The problem has to with the fact that a formula
that has a result of less than 0 can't be converted to a serial code for
dates and times.

If you take this formula
=VALUE(D9-C9-TIME(9,0,0))
you get
-5.55111512312578E-17
as a result (because of rounding error)
this number has no meaning when thinking in terms of dates and times as far
as excel is concerned.


"sudeep" wrote:

I have an worksheet with cell C9=8:30 and D9=17.30 . Then in another cell i
compute the number of hours above 9 that i have been working by
=HOUR((D9-C9)-TIME(9,0,0)). For the above combination i get an error #NUM!.
If i do the same in 2 steps say D10=(D9-C9)-(TIME(9,0,0)) and D11=HOUR(D10)
evrything is fine. Can you tell me why and if there is any way to avoid it?

Reply
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
Changing worksheet cells from within a function James4U2enjoy Setting up and Configuration of Excel 1 October 14th 05 02:16 PM
Hour() function Steven Excel Worksheet Functions 4 October 12th 05 10:22 AM
Automatically up date time in a cell Mark Excel Discussion (Misc queries) 5 May 12th 05 12:26 AM
Conversion SVC Excel Worksheet Functions 9 February 28th 05 02:29 PM
HOW CAN I GET OFFICE 2003 EXCEL BASIC TO NEST FUNCTIONS LIKE EXCE. Robert AS Excel Worksheet Functions 4 December 2nd 04 10:49 AM


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

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

About Us

"It's about Microsoft Excel"