Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
COG COG is offline
external usenet poster
 
Posts: 7
Default Formating a Time Calculation Result

Hi all, I have created a button called TIME with the
following macro attached:

Sub takeoff()
Dim stringval As String
stringval = Format(Now(), "h:mm")
ActiveCell.Value = stringval
End Sub

If I select A1 and click on this button, it will put the
current time in A1. A few minutes later I click on B1
and the TIME button and I get that cuurent time. In C1 I
have the calculation =B1-A1 which gives me the minutes
difference (ex: 10:15 10:47 result :32) What I
need is to change C1 to tenths of an hour. 1-6 minutes
= .1 hr, 7-12 minutes = .2 hr, and so forth.
Any suggestions on how I can do this?
I've tried just dividing C1 by 6 which doesn't work,
tried formating but am not sure I am picking a correct
custom format, etc.
Help please.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Formating a Time Calculation Result

XL stores times as fractional days, so to get hours, multiply by 24:

C1: =CEILING((B1-A1)*24,0.1)

This will work as long as your times don't span midnight. If they do,
you have to compensate for time resetting to 0 at midnight:

C1: =CEILING(((B1-A1)+(B1<A1))*24,0.1)

or

C1: =CEILING(MOD(B1-A1,1)*24,0.1)

In article ,
"COG" wrote:

Hi all, I have created a button called TIME with the
following macro attached:

Sub takeoff()
Dim stringval As String
stringval = Format(Now(), "h:mm")
ActiveCell.Value = stringval
End Sub

If I select A1 and click on this button, it will put the
current time in A1. A few minutes later I click on B1
and the TIME button and I get that cuurent time. In C1 I
have the calculation =B1-A1 which gives me the minutes
difference (ex: 10:15 10:47 result :32) What I
need is to change C1 to tenths of an hour. 1-6 minutes
= .1 hr, 7-12 minutes = .2 hr, and so forth.
Any suggestions on how I can do this?
I've tried just dividing C1 by 6 which doesn't work,
tried formating but am not sure I am picking a correct
custom format, etc.
Help please.

  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Formating a Time Calculation Result

Your solution is getting me close, but didn't quite do
it. Cells A1 and B1 are formated as h:mm, and I had
10:19 and 10:32 in them respectively. When putting in
your formula for cell C1, I got 7 which doesn't make
sense. I was under the impression Excel stored the
date/time as a serial number and that is what is messing
me up. Any other suggestins? Thanks.
-----Original Message-----
XL stores times as fractional days, so to get hours,

multiply by 24:

C1: =CEILING((B1-A1)*24,0.1)

This will work as long as your times don't span

midnight. If they do,
you have to compensate for time resetting to 0 at

midnight:

C1: =CEILING(((B1-A1)+(B1<A1))*24,0.1)

or

C1: =CEILING(MOD(B1-A1,1)*24,0.1)

In article ,
"COG" wrote:

Hi all, I have created a button called TIME with the
following macro attached:

Sub takeoff()
Dim stringval As String
stringval = Format(Now(), "h:mm")
ActiveCell.Value = stringval
End Sub

If I select A1 and click on this button, it will put

the
current time in A1. A few minutes later I click on B1
and the TIME button and I get that cuurent time. In

C1 I
have the calculation =B1-A1 which gives me the minutes
difference (ex: 10:15 10:47 result :32) What I
need is to change C1 to tenths of an hour. 1-6

minutes
= .1 hr, 7-12 minutes = .2 hr, and so forth.
Any suggestions on how I can do this?
I've tried just dividing C1 by 6 which doesn't work,
tried formating but am not sure I am picking a correct
custom format, etc.
Help please.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Formating a Time Calculation Result

Dates *are* integer offsets from a base date. Times are any fractional
remainder, so

3 July 2004 13:05

is stored as 38171.54514 (1900 date system) or 36709.54514 (1904 date
system).

In any case, the 0.54514 represents (13 + 5/60)/24.

But your macro places only the times in the cells, so the date serials
don't matter.

Your result of 7 makes no sense to me either. All of the formulae I gave
you return 0.3 for me, which meets your specifications.


In article ,
wrote:

Your solution is getting me close, but didn't quite do
it. Cells A1 and B1 are formated as h:mm, and I had
10:19 and 10:32 in them respectively. When putting in
your formula for cell C1, I got 7 which doesn't make
sense. I was under the impression Excel stored the
date/time as a serial number and that is what is messing
me up. Any other suggestins? Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
COG COG is offline
external usenet poster
 
Posts: 7
Default Formating a Time Calculation Result

That worked. I redid everything and it worked as you
told me. Thank you sooooo much!
-----Original Message-----
Dates *are* integer offsets from a base date. Times are

any fractional
remainder, so

3 July 2004 13:05

is stored as 38171.54514 (1900 date system) or

36709.54514 (1904 date
system).

In any case, the 0.54514 represents (13 + 5/60)/24.

But your macro places only the times in the cells, so

the date serials
don't matter.

Your result of 7 makes no sense to me either. All of the

formulae I gave
you return 0.3 for me, which meets your specifications.


In article ,
wrote:

Your solution is getting me close, but didn't quite do
it. Cells A1 and B1 are formated as h:mm, and I had
10:19 and 10:32 in them respectively. When putting in
your formula for cell C1, I got 7 which doesn't make
sense. I was under the impression Excel stored the
date/time as a serial number and that is what is

messing
me up. Any other suggestins? Thanks.

.

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
can I use conditional formating with result be hiding a row? Jean Pierre Excel Discussion (Misc queries) 1 March 6th 10 05:32 PM
formating inputbox result in excel NoelH Excel Worksheet Functions 3 May 2nd 06 07:27 AM
How do I use a rounded calculation result in another calculation? vnsrod2000 Excel Worksheet Functions 1 January 26th 05 10:11 PM
How do I use a rounded calculation result in another calculation? vnsrod2000 Excel Worksheet Functions 1 January 26th 05 09:36 PM
Conditional Formating when result is text Lary Excel Worksheet Functions 1 December 16th 04 02:13 AM


All times are GMT +1. The time now is 11:18 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"