Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Feb 2001
    Location
    North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    UCase with Or (Excel 2002)

    Help!
    Why doesn't this work? If I enter "qa1", Qa1, etc in inputBox the Test goes to invalid value eventhough converting to UCase?????
    What am I doing wrong?
    --------------------------------------------
    Dim Qa_Area As Variant

    Qa_Area = Application.InputBox("Enter Qa Supervisor Area: Qa1 or Qa2 " _
    , "zOpenStDevSourceFileQa1 macro", Type:=2)

    If ((UCase(Qa_Area) <> "QA1") Or (UCase(Qa_Area) <> "QA2")) Then
    MsgBox "Invalid entry: " & Qa_Area & " - ending sub!", vbOKOnly, _
    "Valid Qa-Supervisor Input Must be: qa1 or qa2"
    End
    Else
    MsgBox "The Qa_Area input: " & Qa_Area & " - is VALID!"
    End If
    -----------------------------

    Thanks, Phyl

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UCase with Or (Excel 2002)

    Because you need to test using AND instead of OR. (if qa_area equals qa1, the first test is false, but the second True)
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Lounger
    Join Date
    Feb 2001
    Location
    North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UCase with Or (Excel 2002)

    Hmmmm,
    Thanks - seems to work.....
    But I understood that:

    If both expressions evaluate to True, result is True. If either expression evaluates to False, result is False.

    So why is it working?
    Phyl

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UCase with Or (Excel 2002)

    <pre>If ((UCase(Qa_Area) <> "QA1") Or (UCase(Qa_Area) <> "QA2")) </pre>


    The way you've written this test, it will never evaluate to false, because input will always be either not equal to "QA1" or not equal to "QA2". With an OR, the only time the test evaluates to False is if both conditions are false. For that to be the case, the input would have to be equal to both "QA1" and "QA2".

    You've either got to switch to using an AND, or change both of your "<>" to "=". Either way you get the same result (X NOR Y == X' AND Y').

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •