ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using variable from input box (https://www.excelbanter.com/excel-programming/430105-using-variable-input-box.html)

Alfredo_CPA

using variable from input box
 
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

Rick Rothstein

using variable from input box
 
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

--
Rick (MVP - Excel)


"Alfredo_CPA" .(donotspam) wrote in message
...
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



Alfredo_CPA

using variable from input box
 
Thanks a lot!!


"Gary''s Student" wrote:

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

--
Gary''s Student - gsnu200857


"Alfredo_CPA" wrote:

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


Alfredo_CPA

using variable from input box
 
True, that works keeping my original logic (or lack of it... :-)


"Rick Rothstein" wrote:

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

--
Rick (MVP - Excel)


"Alfredo_CPA" .(donotspam) wrote in message
...
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




mudraker[_428_]

using variable from input box
 

When testing a variable cell etc for multiple conditions it is best to
use Select Case statements nstead of If statements

If commands are case sensitve so EPT is not the same as ept or Ept
Use Lcase or Ucase to convert text to all uper or lower case letters

The following code is based on the code in Gary's reply


Sub marine()
Dim s As String
s = Application.InputBox(prompt:="enter LTX or EPT", Type:=2)
Select Case UCase(s)
Case "EPT", "LTX"
MsgBox ("Thanks")
Case Else
MsgBox ("I am leaving")
End Select
End Sub


--
mudraker

If my reply has assisted or failed to assist you I welcome your
Feedback.

www.thecodecage.com
------------------------------------------------------------------------
mudraker's Profile: http://www.thecodecage.com/forumz/member.php?userid=18
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=108422



All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com