Home > Blockchain >  VBA Excel, data validation
VBA Excel, data validation

Time:11-22

I have created a userform where the user needs to fill in some data, to validate the data it has a few checks, at one of the checks i get an error. the error occurs because the combobox (combobox 2 and 3 in the code example below) is not filled (and it should not be filled)and therefore it cannot find the " -" that it is looking for.

how can i change the code to ignore the error and continue with "part 2" i have tried already with on error resume next, and on error goto errorhandler, but this is all not really working for me..

PS. if the first part (if textboxX.value > 0 = false) then the second part (left(Me.ComboBox2.Value, InStr(Me.ComboBox2.Value, " -") - 1) <> Me.ComboBox1 Then) shouldn't even been run

part 1:

If TextBox9.Value > 0 And Left(Me.ComboBox2.Value, InStr(Me.ComboBox2.Value, " -") - 1) <> Me.ComboBox1 Then
    MsgBox "The selected bagtag of size 17 does not match with selected BIN"
    Exit Sub
    End If

part 2:

If TextBox10.Value > 0 And Left(Me.ComboBox3.Value, InStr(Me.ComboBox3.Value, " -") - 1) <> Me.ComboBox1 Then
    MsgBox "The selected bagtag of size 19 does not match with selected BIN"
    Exit Sub
    End If

CodePudding user response:

Here is what I suggest: separate the 2 conditions so you face the second one only if the first one is True:

If TextBox9.Value > 0 Then
    If InStr(Me.ComboBox2.Value, " -") > 0 Then
        If Left(Me.ComboBox2.Value, InStr(Me.ComboBox2.Value, " -") - 1) <> Me.ComboBox1 Then
            MsgBox "The selected bagtag of size 17 does not match with selected BIN"
            Exit Sub
        End If
    End If
End If

Hope this helps

  • Related