View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default Sum work hours to hours & nearest 10th of an hour

On the active sheet that represents a given month of the year:

Column D = employee who has signed in
Column E = Date in
Column F = sign in time
Column G = Date out
Column H = sign out time

Sarah 7/16/2014 9:44 PM 7/16/2014 10:22 PM
Jaydee 7/16/2014 9:44 PM 7/16/2014 10:48 PM
Frank 7/16/2014 10:51 PM

Column M = A unique list of all employees.

Employees will be signed in and out several times.
Not every employee in column M will be signed in (some may not work that month)
Some will be signed in but not signed out when the code is run during the course of the month.

Trying to get this line to return all hours worked and minutes to the nearest 10th to column N next to employee name.

ie. every 6 minutes = .1 of an hour.


cM.Offset(, 1) = (cD.Offset(, 4) - cD.Offset(, 2)) + (cM.Offset(, 1))


So each time code is run, column N is cleared and all hours are updated.

What I have right now is values that pretty much don't mean anything to me, and some are negative.

Column N formatted as General until I know what it should be.

I would expect the code to be run on the active sheet so it could used for all months, with each month on a sheet.

Thanks,
Howard


Sub NameAndHours()

Dim Mname As Range, Dname As Range
Dim cM As Range, cD As Range
Dim i As Long

Set Mname = Range("M2:M" & Cells(Rows.Count, "M").End(xlUp).Row)
Set Dname = Range("D2:D" & Cells(Rows.Count, "D").End(xlUp).Row)

For Each cM In Mname

For Each cD In Dname

If cM = cD Then

cM.Offset(, 1) = (cD.Offset(, 4) - cD.Offset(, 2)) + (cM.Offset(, 1))

End If

Next

Next

End Sub