'If Textbox.Value = ("",<0,>1,OR <>"x") Then

When building an IF Then statement, I want to call attention to a textbox when the user form data entered is NOT one of the three approved options (1,0, or X)...

What is the best way to write that?

Here's what I have:

If Textbox.Value = ("",<0,>1,OR <>"x") Then 
   Textbox.BackColor = rgbPink
   Textboxlabel.ForeColor = rgbRed
   Textbox.SetFocus
   Exit Sub
End If


Solution 1:[1]

you want "if not equal to" ? in this case you should use <> :

If Textbox.Value <>"" OR Textbox.Value<>0 OR Textbox.Value<>1 OR Textbox.Value<>"x" Then 
   Textbox.BackColor = rgbPink
   Textboxlabel.ForeColor = rgbRed
   Textbox.SetFocus
   Exit Sub
End If 

This will enter in the "if" if Textbox.value is different of "", or 0, or 1 or "x"....

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1