Thanks Paul, It appears to work as you said. However thinking this through a bit more since I dont know for sure what hours they will be working each day I decided to loop through the range and add up all the working minutes they work.
The problem I have now is I am returning the number of minutes but I want to place how many hours and minutes back into the cell as hh:mm.
I'm trying this after I get the minutes total(myresults) in this case its 2971 minutes which is 49 hours and 31 minutes
Hours = Int(myresults / 60) 'get hours from myresults (49)
Minutes = myresults Mod 60 'get minutes from myresults (31)
Now I want to place 49:31 back in the cell, This is the part that isnt working not sure which method is correct to use or if both are wrong because it appears results is a text value "49:31" and not a time value, but when I change the format of the cell it becomes 01:31
Can someone advise which is the corret method or another method?
Thank You, Mike
results = Hours & ":" & Minutes
Cells(8, "B") = results
Cells(8, "B").NumberFormat = "hh:mm"
or
results = Format(Hours, "0#") & ":" & Format(Minutes, "0#")
Cells(8, "B") = results
Cells(8, "B").NumberFormat = "hh:mm"
Here is how it's layed out in the script which seems to work till I change the format of the cell?
Range("K21:K" & lrow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"O21"), Unique:=True
dlrow = Cells(Rows.Count, "O").End(xlUp).Row
Range("A21:N21").AutoFilter
For i = 22 To dlrow
Range("A21:N21").AutoFilter Field:=11, Criteria1:=Cells(i, "O").Value
With wks.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
Stop
Else
Set rng = wks.AutoFilter.Range
With rng
Lrnglrow = Cells(Rows.Count, 1).End(xlUp).Row
frngrow = .Offset(1, 0).SpecialCells(xlCellTypeVisible).Row
Cells(frngrow, "P").FormulaR1C1 = "=SUM(RC[-5],RC[-6])"
Cells(frngrow, "P").NumberFormat = "mm/dd/yyyy hh:mm:ss"
Cells(Lrnglrow, "P").FormulaR1C1 = "=SUM(RC[-5],RC[-6])"
Cells(Lrnglrow, "P").NumberFormat = "mm/dd/yyyy hh:mm:ss"
myresults = myresults + DateDiff("n", Cells(frngrow, "P"), Cells(Lrnglrow, "P"))
End With
End If
Next i
Stop
Range("A21:N21").AutoFilter
Cells(6, "B") = Cells(22, "P")
Cells(6, "B").NumberFormat = "[$-F400]h:mm:ss AM/PM" 'returns First start time
Cells(7, "B") = Cells(lrow, "P")
Cells(7, "B").NumberFormat = "[$-F400]h:mm:ss AM/PM" ' Returns last end time
Hours = Int(myresults / 60) 'get hours from myresults
Minutes = myresults Mod 60 'get minutes from myresults
results = Hours & ":" & Minutes
results = Format(Hours, "0#") & ":" & Format(Minutes, "0#")
Cells(8, "B") = results
Cells(8, "B").NumberFormat = "hh:mm"
Bookmarks