Adding a number of hours

omarelhosseini

New Member
Joined
Jun 13, 2019
Messages
17
When adding a number of hours in column C
Its effect is reflected in columns A and B

add hour to date.xlsm
ABC
1Trip DateTrip TimeNumber Of Hours To Added
211/04/202205:25:00
311/04/202213:45:00
411/04/202214:00:00
511/04/202221:35:00
610/04/202205:25:00
710/04/202212:45:00
810/04/202221:35:00
910/04/202222:45:00
1009/04/202205:25:00
1112/04/202208:15:00
1209/04/202217:35:00
1309/04/202221:45:00
1408/04/202205:25:00
1508/04/202208:00:00
1608/04/202208:00:00
1708/04/202210:00:00
1808/04/202222:00:00
1908/04/202211:00:00
2008/04/202216:00:00
2108/04/202221:35:00
2207/04/202206:20:00
2307/04/202210:15:00
2407/04/202212:50:00
2507/04/202214:30:00
2608/04/202208:50:00
2707/04/202216:10:00
2807/04/202222:45:00
2906/04/202205:25:00
3006/04/202221:35:00
3105/04/202205:25:00
3205/04/202210:00:00
3305/04/202211:25:00
3405/04/202221:35:00
3505/04/202222:45:00
3604/04/202205:25:00
3704/04/202214:00:00
3803/04/202205:40:00
3903/04/202212:45:00
4003/04/202212:45:00
4103/04/202221:45:00
4203/04/202222:45:00
4302/04/202205:40:00
4407/04/202208:00:00
4502/04/202217:35:00
4602/04/202221:35:00
4701/04/202205:40:00
4801/04/202209:30:00
4901/04/202211:00:00
5001/04/202211:00:00
5101/04/202212:00:00
5201/04/202216:00:00
5301/04/202221:35:00
Sheet2
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Correct me if I was wrong:
A1: 11-Apr (in real date at 0:00 , integer)
B1: 05:25:00 (in real time)

Now you want to add hours in C1

1) input C1 = 20:00:00
2) A1 to become: 12-Apr
3) B1 to become 01:25:00
4) C1 back to blank cell

is it the case?
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim d As Double, t As Double
If Target.Column <> 3 Then Exit Sub
If Target.Rows.Count > 1 Then Exit Sub
If Target.Value = "" Or Not IsNumeric(Target) Then Exit Sub
d = Target.Offset(0, -2).Value
t = Target.Offset(0, -1).Value
    Target.Offset(0, -2).Value = Int(d + t + Target.Value)
    Target.Offset(0, -1).Value = ((t + Target.Value) * 1000 Mod 1000) / 1000
Target.ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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