Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
SUMIF statement with AND statement | Excel Discussion (Misc queries) | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |