After finally getting my spreadsheet to do exactly what I want it to do, the payroll department made a change...grrr.
Now the goal is to automatically round the time to the nearest 15 minute increment within the same cell. I also want to total these times at the end of the row to show hours and minutes instead of converted to decimals. I already have code to enter a time in one cell and it automatically insert the colon without having to type it. Another drawback, we have some shifts that work past midnight. This is overcome by entering the date and the time, and I don't have any problems with that...yet.
My current VBA:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vVal
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("B5:I329")) Is Nothing Then Exit Sub
With Target
vVal = Format(.Value, "0000")
If IsNumeric(vVal) And Len(vVal) = 4 Then
Application.EnableEvents = False
.Value = Left(vVal, 2) & ":" & Right(vVal, 2)
.NumberFormat = "[h]:mm"
End If
End With
Application.EnableEvents = True
End Sub
And the current formula for calculating the row of times:
=+((C5-B5+E5-D5+G5-F5+I5-H5)*1)*24
Example of what I would enter on the spreadsheet:
B5=0550 C5=1536 D5=1605 E5=1805 J5=11.77 (Total converted to decimal)
What I want each cell to look like:
B5=05:45 C5=15:30 D5=16:00 E5=18:00 J5=12.30
Sorry if this is confusing, but I have racked my brain for the past week. Let me know if you'd like to see the actual spreadsheet.
Thanks
Now the goal is to automatically round the time to the nearest 15 minute increment within the same cell. I also want to total these times at the end of the row to show hours and minutes instead of converted to decimals. I already have code to enter a time in one cell and it automatically insert the colon without having to type it. Another drawback, we have some shifts that work past midnight. This is overcome by entering the date and the time, and I don't have any problems with that...yet.
My current VBA:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vVal
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("B5:I329")) Is Nothing Then Exit Sub
With Target
vVal = Format(.Value, "0000")
If IsNumeric(vVal) And Len(vVal) = 4 Then
Application.EnableEvents = False
.Value = Left(vVal, 2) & ":" & Right(vVal, 2)
.NumberFormat = "[h]:mm"
End If
End With
Application.EnableEvents = True
End Sub
And the current formula for calculating the row of times:
=+((C5-B5+E5-D5+G5-F5+I5-H5)*1)*24
Example of what I would enter on the spreadsheet:
B5=0550 C5=1536 D5=1605 E5=1805 J5=11.77 (Total converted to decimal)
What I want each cell to look like:
B5=05:45 C5=15:30 D5=16:00 E5=18:00 J5=12.30
Sorry if this is confusing, but I have racked my brain for the past week. Let me know if you'd like to see the actual spreadsheet.
Thanks