我正在尝试创建一个VBA代码,用于计算单击某个操作复选框后的已用时间。
我和VBA一直待在一起,所以我不会流利。有人可以帮我处理这段代码吗?
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
答案 0 :(得分:0)
format the x3 value
更改最后一个代码行,如下所示
TextBox4.Value = Format(X3, "hh:mm:ss")
答案 1 :(得分:0)
没有解决您的主要查询,这似乎与格式有关,但您应该在IF中使用多行块并使用Else而不是另一个if!
Private Sub CheckBox1_Click()
X1 = Now
If CheckBox1.Value = True Then
TextBox1.Value = Now
' i dont think u need the following here but put here to show multi line if
' keepa button to reset both text boxes
TextBox2.Value = "00:00"
elseif
TextBox1.Value = Null
end if
'keep in reset button click
'If CheckBox1.Value = False Then TextBox2.Value = Null
End Sub