Okay, as I mentioned, you could also do this during the calculation stage, rounding before subtracting, but keep the sign in/out times as is. However, this code will modify your times to the nearest 6 minutes. Then the calculations need to be modified,
i.e. in F9, simplify that to
=((E9-B9)-(D9-C9))*24
An explaination. Excel uses the day as the unit of measurement with time and dates. So an hour = 1/24 = 0.041667, a minute = 1/(60*24) = 0.000694 and 6 minutes = 6/(60*24) = 0.0041667. In the code, I use the Excel Function MROUND which rounds to the nearest value as specified by the second argument in the function (I used 0.00417). Excel formats that as time.
To enter your code into the workbook, Copy it,
Right click on the sheet tab and "View code" (this will open the VBA editor)
Paste the code into the large white text box on the right side of the VBA editor.
I've attached your example, already modified.
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Count = 1 Then
If Intersect(Target, Range("B9:E23")) Is Nothing Then Exit Sub
Target = WorksheetFunction.MRound(Target.Value, 0.00417)
End If
End Sub
Is that what you were looking for?
Bookmarks