Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working with IF's (A-XP/Win 2k Sr1)

    When working with "If" statements how do I tie in multiple criteria for the statement? Exapmle: I want to say "If strVar = 1 or 2 or 3 then"... What is the correct method to do the OR's? It doesn't seem to work correctly and I know it's a syntax thing. I can get things to work using elseif statements but this causes extra lines of code.

    Thanks,
    Mark

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Working with IF's (A-XP/Win 2k Sr1)

    In an If-End If, you always have to use the full equivalency expression. So in your example, you have to say "If strVar = 1 or strVar = 2 or strVar = 3 Then ...."

    I wouldn't worry too much about extra lines of code. It's a tradeoff in readability versus lines. I hate to encounter code where everything is compressed as much as possible because it takes so long to figure out what the programmer was actually doing.
    Charlotte

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with IF's (A-XP/Win 2k Sr1)

    Cool... I'll stick with the Elseif's then.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Working with IF's (A-XP/Win 2k Sr1)

    Hi Mark,
    Depending on what you're doing, you may find that a Select Case statement is easier to read/deal with as well as quicker in code.
    Just a thought.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Working with IF's (A-XP/Win 2k Sr1)

    I second that motion! I use Select Cases a lot.
    Charlotte

Posting Permissions

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