Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Don Don is offline
external usenet poster
 
Posts: 21
Default Help with Time Calculations

On my worksheet, my user is entering start and stop times for employees and
then in a separate cell, displaying the hours worked. I have been using the
hour(b1-a1)+hour(d1-c1), etc. cell functions to calculate the hours. But
now, the times are changing and I would like to use the code to calculate
the hours. The below is what I have, but it doesn't calculate the hours
correctly......I've used 7:30am and 4pm in cells a1 thru j1......The result
it gives me is 18:30 and it should be 40:00......What am I doing wrong?

Dim daystart, dayend, dailyhrs, weekhrs As Date
For i = 0 To 6
daystart = ActiveCell.Value
ActiveCell.Cells(1, 2).Activate
dayend = ActiveCell.Value
dailyhrs = dayend - daystart
weekhrs = weekhrs + dailyhrs
ActiveCell.Cells(1, 2).Activate
Next i
Range("a3").Select
ActiveCell.FormulaR1C1 = weekhrs

Thanks,
Don


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Help with Time Calculations

Hi
format your target cell with the custom format
[hh]:mm

--
Regards
Frank Kabel
Frankfurt, Germany


Don wrote:
On my worksheet, my user is entering start and stop times for
employees and then in a separate cell, displaying the hours worked. I
have been using the hour(b1-a1)+hour(d1-c1), etc. cell functions to
calculate the hours. But now, the times are changing and I would like
to use the code to calculate the hours. The below is what I have, but
it doesn't calculate the hours correctly......I've used 7:30am and
4pm in cells a1 thru j1......The result it gives me is 18:30 and it
should be 40:00......What am I doing wrong?

Dim daystart, dayend, dailyhrs, weekhrs As Date
For i = 0 To 6
daystart = ActiveCell.Value
ActiveCell.Cells(1, 2).Activate
dayend = ActiveCell.Value
dailyhrs = dayend - daystart
weekhrs = weekhrs + dailyhrs
ActiveCell.Cells(1, 2).Activate
Next i
Range("a3").Select
ActiveCell.FormulaR1C1 = weekhrs

Thanks,
Don


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
Time calculations for Scheduled vs Actual Employee Time and Wages The Caterer Excel Discussion (Misc queries) 4 November 29th 09 11:51 PM
Time calculations for Scheduled Time vs. Actual Time Worked The Caterer Excel Discussion (Misc queries) 1 November 29th 09 08:08 AM
Time calculations for Scheduled vs Actual Employee Time and Wages The Caterer Excel Discussion (Misc queries) 2 November 29th 09 12:20 AM
Time difference calculations, daylight savings time, Excel Tim Excel Discussion (Misc queries) 1 December 28th 06 04:18 PM
convert time imported as text to time format for calculations batfish Excel Worksheet Functions 3 October 27th 05 11:24 PM


All times are GMT +1. The time now is 02:49 PM.

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"