D
Don
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
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