using variable from input box

  • Thread starter Thread starter Alfredo_CPA
  • Start date Start date
A

Alfredo_CPA

I have this code:
MyLocation = InputBox("Enter LTX or EPT", "Pick Option")
If MyLocation = "" Or MyLocation <> "LTX" Or MyLocation <> EPT Then
MsgBox "Nothing entered/Cancel or Wrong Location"
Exit Sub
End If

Of course is not working. I need to exist sub if user puts something
different than EPT or LTX (the same if user press cancel or press ok without
typing anything)

I think is not working becasuse the two "Or" exclude the other option (e.g.
if user types LTX then Mylocation <> EPT...)

How can I solve this?

Thanks
 
The problem is that "LTX" will satisfy the MyLocation<>"EPT" and "EPT" will
satisfy the MyLocation<>"LTX" and, because you OR'ed them, they and every
other entry will satisfy your conditions. I would do it like Gary''s Student
posted, but an alternative using the structure I think you were after would
be this...

If MyLocation = "" Or (MyLocation <> "LTX" And MyLocation <> "EPT") Then
 
Thanks a lot!!


Gary''s Student said:
Sub marine()
Dim s As String
s = Application.InputBox(prompt:="enter LTX or EPT", Type:=2)
If s = "EPT" Or s = "LTX" Then
MsgBox ("Thanks")
Else
MsgBox ("I am leaving")
End If
End Sub
 
Back
Top