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

I'm still new at this VB stuff, and did not know how to do An Or in the If
Statement.

IF this OR that Then
blahblahblah...
End IF

Thanks for your help whoever you may be,
Thomas :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default If OR Statement...

You've got it right:

Public Function foo(this As Boolean, that As Boolean) As String
If this Or that Then
foo = "blahblahblah..."
End If
End Function


In article ,
thomas wrote:

IF this OR that Then
blahblahblah...
End IF

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If OR Statement...

Just to add, if you were testing a range equal to either of two values as an
example

If Range("A1") 10 or Range("A1") < 1 then
msgbox "Out of bounds
End If

You can't do something like

if Range(A1) 10 or < 1 then

Each side of the OR must a an expression that can be evaluated to or coerced
to a boolean value.
--
Regards,
Tom Ogilvy

"thomas" wrote in message
...
I'm still new at this VB stuff, and did not know how to do An Or in the If
Statement.

IF this OR that Then
blahblahblah...
End IF

Thanks for your help whoever you may be,
Thomas :)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default If OR Statement...



thomas wrote:
I'm still new at this VB stuff, and did not know how to do An Or in the If
Statement.

IF this OR that Then
blahblahblah...
End IF

Thanks for your help whoever you may be,
Thomas :)


just use Or between boolean statements:

If A = B Or A = C Then
msgbox "A is B or C"
End If

The only thing to watch out for is that, unlike in say C, VBA's "Or" is
not evaluated via short-circuit evaluation. This means that in

P Or Q

Q is evaluated even if P is true. Thus

If B = 0 Or 1/B 5 Then ...

throws a run-time division by zero error if B happens to be zero, so
you would be forced into a more verbose way, perhaps involving
if-then-else or nested ifs for that sort of thing. VBA's "And" has the
same lack of short-circuit evaluation, which is one of the more
annoying things about VBA

-John Coleman

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
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
SUMIF statement with AND statement Eric D Excel Discussion (Misc queries) 2 July 14th 08 07:24 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 02:29 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"