Posts by thomask_23


    I am new to VBA and working on a userform. I have multiple combo boxes for which I would like to restrict the user to only being able to enter values between 0 and 5.

    I have got the code to work to provide an error message if the value entered is not numeric. Is there a simple line of code I can add to this (And statement?) which would prompt the error message when values outside of 0-5 are entered?

    1. Private Sub ComboBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    2. If Not IsNumeric(ComboBox2.Value) Then
    3. MsgBox "please enter a number between 0 and 5", vbCritical
    4. ComboBox2.SelStart = 0
    5. ComboBox2.SelLength = Len(ComboBox2.Value)
    6. Cancel = True
    7. End If
    8. End Sub