vendredi 4 novembre 2016

vba command button not executing in sequence

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

So here is the sequence of events that just happened trying to run this command button code from a userform:

  • choosing no options from any listbox (to invoke errors and test code), I hit the command button. It gave me the error from the 2nd if-block. I tried again, same result.
  • i went into the code and did various innocuous things like moving position of the cursor and re-saving the vba code.
  • brought up user form again, left listboxes unselected again, and hit command button. it went to 1st block. i said "great". tried again. same.
  • user form up. selected option so 1st block would be skipped. it gave me 3rd block error.

does not seem to have rhyme or reason why it is doing this, and i'm going batty now. the only other option is making a single ginormous nested if-loop to include everything, but that is last resort.

Aucun commentaire:

Enregistrer un commentaire