VBA新手在这里。这是代码:
Dim oper_state As Integer
Dim r As Integer
Dim c As Integer
Dim timehr As Double
Dim timemin As Double
Public Sub UserForm_Initialize()
r = 0
c = 0
AAATemp.Value = ""
LineTemp.Value = ""
Operational.Value = False
Deactivated.Value = False
AAATemp.SetFocus
HOPA.Output.Caption = "Insert Temperature Data"
End Sub
Public Sub Deactivated_Click()
If Deactivated = True Then
oper_state = 0
End If
End Sub
Public Sub Operational_Click()
If Operational = True Then
oper_state = 1
End If
End Sub
Public Sub AAATemp_Change()
If AAATemp.Value < 18.3 Then
r = 3
ElseIf (AAATemp.Value >= 18.3 And AAATemp.Value <= 19.4) Then
r = 4
ElseIf (AAATemp.Value >= 19.4 And AAATemp.Value <= 20.6) Then
r = 5
ElseIf (AAATemp.Value >= 20.6 And AAATemp.Value <= 21.7) Then
r = 6
ElseIf (AAATemp.Value >= 21.7 And AAATemp.Value <= 22.8) Then
r = 7
ElseIf (AAATemp.Value >= 22.8 And AAATemp.Value <= 23.9) Then
r = 8
ElseIf (AAATemp.Value >= 23.9 And AAATemp.Value <= 25) Then
r = 9
ElseIf (AAATemp.Value >= 25 And AAATemp.Value <= 26.1) Then
r = 10
ElseIf (AAATemp.Value >= 26.1 And AAATemp.Value <= 27.2) Then
r = 11
ElseIf (AAATemp.Value >= 27.2 And AAATemp.Value <= 28.3) Then
r = 12
ElseIf (AAATemp.Value >= 28.3 And AAATemp.Value <= 29.4) Then
r = 13
ElseIf (AAATemp.Value >= 29.4 And AAATemp.Value <= 30.6) Then
r = 14
Else
r = 15
End If
If (r = 0 Or c = 0) Then
HOPA.Output.Caption = "Insert Temperature Data"
ElseIf (oper_state = 1 And r <> 0 And c <> 0) Then
timehr = Worksheets("HOPA Times").Cells(r, c).Value
timemin = timehr * 60
If timehr = 9999 Then
HOPA.Output.Caption = "Inf"
ElseIf timehr < 9999 Then
HOPA.Output.Caption = timehr & " (" & timemin & " minutes)"
End If
ElseIf (oper_state = 0 And r <> 0 And c <> 0) Then
r = r + 16
timehr = Worksheets("HOPA Times").Cells(r, c).Value
timemin = timehr * 60
If timehr = 9999 Then
HOPA.Output.Caption = "Inf"
ElseIf timehr < 9999 Then
HOPA.Output.Caption = timehr & " (" & timemin & " minutes)"
End If
End If
End Sub
Public Sub LineTemp_Change()
If LineTemp.Value < 14.7 Then
c = 2
ElseIf (LineTemp.Value >= 14.7 And LineTemp.Value <= 15.8) Then
c = 3
ElseIf (LineTemp.Value >= 15.8 And LineTemp.Value <= 16.9) Then
c = 4
ElseIf (LineTemp.Value >= 16.9 And LineTemp.Value <= 18) Then
c = 5
ElseIf (LineTemp.Value >= 18 And LineTemp.Value <= 19.2) Then
c = 6
ElseIf (LineTemp.Value >= 19.2 And LineTemp.Value <= 20.3) Then
c = 7
ElseIf (LineTemp.Value >= 20.3 And LineTemp.Value <= 21.4) Then
c = 8
ElseIf (LineTemp.Value >= 21.4 And LineTemp.Value <= 22.5) Then
c = 9
ElseIf (LineTemp.Value >= 22.5 And LineTemp.Value <= 23.6) Then
c = 10
ElseIf (LineTemp.Value >= 23.6 And LineTemp.Value <= 24.7) Then
c = 11
ElseIf (LineTemp.Value >= 24.7 And LineTemp.Value <= 25.8) Then
c = 12
Else
c = 13
End If
If (r = 0 Or c = 0) Then
HOPA.Output.Caption = "Insert Temperature Data"
ElseIf (oper_state = 1 And r <> 0 And c <> 0) Then
timehr = Worksheets("HOPA Times").Cells(r, c).Value
timemin = timehr * 60
If timehr = 9999 Then
HOPA.Output.Caption = "Inf"
ElseIf timehr < 9999 Then
HOPA.Output.Caption = timehr & " (" & timemin & " minutes)"
End If
ElseIf (oper_state = 0 And r <> 0 And c <> 0) Then
r = r + 16
timehr = Worksheets("HOPA Times").Cells(r, c).Value
timemin = timehr * 60
If timehr = 9999 Then
HOPA.Output.Caption = "Inf"
ElseIf timehr < 9999 Then
HOPA.Output.Caption = timehr & " (" & timemin & " minutes)"
End If
End If
End Sub
这些值是通过UserForm确定的。 UserForm有两个单选按钮,两个文本输入和一个标签(用于输出)。标签根据单选按钮选择和用户输入动态变化 - 至少,这是我希望它做的。
不幸的是,标签输出仅在我更改AAA或LineTemp文本框时更新。单击单选按钮后没有任何反应。如果我确实更改了单选按钮选择,我需要进入并更改文本框输入(通常只删除小数并重新输入)。
我已经尝试在变更子中移动单选按钮逻辑,但显然这不起作用。有没有办法让Excel查看整个表单并检查更改?