vba命令按钮不按顺序执行

时间:2016-11-04 19:48:08

标签: vba excel-vba if-statement excel

Private Sub NewCycle_Click()

If ThrusterList.Value <> "Thr A Bank" And ThrusterList.Value <> "Thr B Bank" _
And ThrusterList.Value <> "Both" Then
    Unload Me
    Cells(20, 1).Value = "thr error"
    Exit Sub
End If

If GammaList.Value <> "User Provided" Then
    Unload Me
    Cells(20, 1).Value = "gam error"
    Exit Sub
End If

If ThrusterList.Value = "Thr A Bank" Or ThrusterList.Value = "Both" Then
    If T1Aval.Value = "" Or T2Aval.Value = "" Or T3Aval.Value = "" Or T4Aval.Value = "" Then
        Unload Me
        Cells(20, 1).Value = "ta error"
        Exit Sub
    End If
End If

If ThrusterList.Value = "Thr B Bank" Or ThrusterList.Value = "Both" Then
    If T1Bval.Value = "" Or T2Bval.Value = "" Or T3Bval.Value = "" Or T4Bval.Value = "" Then
        Unload Me
        Cells(20, 1).Value = "tb error"
        Exit Sub
    End If
End If

以下是尝试从用户窗体运行此命令按钮代码时发生的事件序列:

  • 从任何列表框中选择没有选项(调用错误和测试代码),我点击命令按钮。它给了我第二个if-block的错误。我再次尝试,结果相同。
  • 我进入代码并做了各种无关紧要的事情,比如移动光标位置并重新保存vba代码。
  • 再次启动用户表单,再次取消选中左侧列表框,然后单击命令按钮。它去了第一街区。我说&#34;伟大&#34;。再试一次。相同。
  • 用户表格。选择的选项,因此将跳过第1个块。它给了我第3次阻止错误。

似乎没有押韵或理由为什么这样做,而且我现在正在打屁股。唯一的另一个选择是制作一个巨大的嵌套if-loop来包含所有内容,但这是最后的选择。

0 个答案:

没有答案
相关问题