VBA-Excel: Subtract date and time from two NOWs and display it in a textbox
Hello ALL,
I am trying to create a VBA code that calculates elapsed time after a certain action checkbox is clicked.
On clicking checkbox1 NOW is captured and display in textbox1.
on clicking checkbox2, NOW is displayed in textbox3 and the elapsed time (value in textbox3 - value in textbox1) needs to be displayed in textbox4 in hours and minutes format accurately. Which i am unable to do after trying and googling for different codes.
I have remained on and off with VBA, so i am not fluent. Can someone help me with the piece of code?
Dim X1 As Date
Private Sub CheckBox1_Click()
X1 = Now
If CheckBox1.Value = True Then TextBox1.Value = Now
If CheckBox1.Value = False Then TextBox1.Value = Null
If CheckBox1.Value = True Then TextBox2.Value = "00:00"
If CheckBox1.Value = False Then TextBox2.Value = Null
End Sub
Private Sub CheckBox2_Click()
Dim X2 As Date
Dim X3 As Date
Dim X4 As Date
X2 = Now
If CheckBox2.Value = True Then TextBox3.Value = Now
If CheckBox2.Value = False Then TextBox3.Value = Null
If CheckBox2.Value = False Then TextBox4.Value = Null
X3 = X2 - X1
TextBox4.Value = X3
End Sub
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago