I manage two teams at my office and need to keep track of how much time is spent with each team. I found a VB code which automatically enters the current time in column B whenever data is populated in column A. My columns are as follows:
Column A = Team Red or Team Blue (selected from a list using data validation)
Column B = Current Time is automatically entered when Team A or Team B is selected from the list
Column C = Needs to subtract the time from the previous row
A cell in column C has the formula "=B4-B3"
The problem is they are not calculating properly. If the difference between B4 and B3 is :10 minutes it is displaying :09 minutes. I formated the cells so they share the same time format. I also tried entering the formula "=B4-B3+:01" which returns an error.
The code in VB is:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A3:A999"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "hh:mm"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub
Column A = Team Red or Team Blue (selected from a list using data validation)
Column B = Current Time is automatically entered when Team A or Team B is selected from the list
Column C = Needs to subtract the time from the previous row
A cell in column C has the formula "=B4-B3"
The problem is they are not calculating properly. If the difference between B4 and B3 is :10 minutes it is displaying :09 minutes. I formated the cells so they share the same time format. I also tried entering the formula "=B4-B3+:01" which returns an error.
The code in VB is:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A3:A999"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "hh:mm"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub