I am trying to create a VBA code that calculates elapsed time after a certain action checkbox is clicked.
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
format the x3 value
change the last code line as below
TextBox4.Value = Format(X3, "hh:mm:ss")