VBA code: calculating time difference
Closed
vathsala
-
Updated on Jan 10, 2022 at 12:04 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen January 16, 2023 - Nov 4, 2021 at 12:37 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen January 16, 2023 - Nov 4, 2021 at 12:37 PM
Related:
- VBA code: calculating time difference
- Huawei test code - Guide
- Samsung keypad reset code - Guide
- Whatsapp verification code online - Guide
- Mega stone cheat code - Guide
- Samsung volume increase code - Guide
1 response
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 16, 2023
549
Nov 4, 2021 at 12:37 PM
Nov 4, 2021 at 12:37 PM
Hi Vathsala,
Not sure how your sheet is made up, but when you have times like "hh:mm:ss" in column A and you want the time difference in column D, then you can give the code below a try:
Best regards,
Trowa
Not sure how your sheet is made up, but when you have times like "hh:mm:ss" in column A and you want the time difference in column D, then you can give the code below a try:
Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Columns("A")) Is Nothing Then Exit Sub If Target.Cells.Count > 1 Then Exit Sub With Target.Offset(0, 3) .NumberFormat = "hh:mm:ss" .Value = Target.Offset(1, 0).Value - Target.Value If .Row = 2 Then Exit Sub If .Value < 0 Then .Value = vbNullString End With With Target.Offset(-1, 3) .NumberFormat = "hh:mm:ss" .Value = Target.Value - Target.Offset(-1, 0).Value End With End Sub
Best regards,
Trowa