Not Subtracting Time Properly

DDT123

New Member
Joined
Aug 9, 2011
Messages
41
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
No promises, but I think its a rounding issue in conjunction with your number formatting of "hh:mm". Try: =MROUND(B6-B5,0.000694444444444444)
 
Upvote 0
I tried it several different ways... How would the line appear?

.NumberFormat = "hh:mm"


Or, do you know a code I could use for static time? Maybe I could have Column B displaying my start time and a new Column C displaying my end time. Followed by a Column D which will calculate the difference between C and B.
I'd like a macro so I could insert a button I can press whenever someone from either team requests my assistance.
 
Upvote 0
I am sorry, but I do not think I am understanding. I meant for you to try replacing the formula (A cell in column C has the formula "=B4-B3") with the formula I offered. In essence, I think the "hh:mm" is just truncating, so I think/hope the formula would round it to the val of interest (the minute).
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,882
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top