Consulting

Results 1 to 3 of 3

Thread: Solved: If Statement Insanity

  1. #1

    Solved: If Statement Insanity

    What is wrong with this IF statement?

    [vba]
    If Not ((UCase(countryRange.Value) = "US") Or (UCase(countryRange.Value) = "PR") Or (UCase(countryRange.Value) = "VI") Or (UCase(countryRange.Value) = "GU")) Then ' if not US or PR or GU or VI
    Debug.Print countryRange.Value
    [/vba]
    This is getting a lot of rows returning saying "US" even though the IF statement explicitly catches the US country code..What am I doing wrong?
    Last edited by Aussiebear; 12-27-2012 at 02:39 AM. Reason: Adjusted the tags to the correct usage

  2. #2
    Nevermind, i forgot to Trim the variable i was checking...

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    This syntax might be more readable

    [VBA]Select Case UCase(countryRange.Value))
    Case "US", "PR", "VI", "GU"
    ' do nothing
    Case Else
    Debug.Print countryRange.Value
    End Select[/VBA]

Posting Permissions

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