Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default If statement with "OR"

Is there a shorthand way of working "OR" into an if statement in a
similar as used in the CASE statement

if Person = "Peter", "Paul", "John" then...

along the lines of
Select Case Person
Case "Peter","Paul","John"...

if Person = "Peter" or Person = "Paul" or Person = "John" then...
is a bit bulky
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default If statement with "OR"

"Laurence Lombard" wrote:
Is there a shorthand way of working "OR" into an
if statement in a similar as used in the CASE statement
if Person = "Peter", "Paul", "John" then...
along the lines of
Select Case Person
Case "Peter","Paul","John"...


Not that I know of. In fact, Select Case __is__ the "shorthand" that I use
for that purpose.

Even if there were a "shorthand" form for an If statement, it probably would
be implemented inefficiently.

In VBA, the If conditional expression is fully evaluated. It is not
evaluated left-to-right only as far as necessary, as is the case in some
other computer languages. So:

If Person = "Peter" Or Person = "Paul" Or Person = "John" Then

performs 3 comparisons and ORs the results before determining whether or not
to execute the Then part.

In contrast:

Select Person
Case "Peter", "Paul", "John"

tests each case in order, and it stops the comparisons and goes to the
appropriate case as soon as a true condition is encountered.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
embedding "ISERROR" function into an "IF" statement [email protected] Excel Worksheet Functions 8 January 4th 07 12:01 AM
Call a sub statement in "Personal Macro Workbook" from "ThisWorkbo QC Coug Excel Programming 1 August 26th 05 07:09 PM
vba: How do I write a "For Each Statement" nested in a "With Statement"? Mcasteel[_30_] Excel Programming 1 November 8th 04 09:47 PM
vba: How do I write a "For Each Statement" nested in a "With Statement"? Mcasteel[_27_] Excel Programming 1 November 8th 04 09:23 PM


All times are GMT +1. The time now is 08:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"