View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Joe User[_2_] Joe User[_2_] is offline
external usenet poster
 
Posts: 905
Default VBA IF THEN with an OR

"Papa Jonah" wrote:
I would like to have an IF Then statement that is of the ilk, If this or
that
then...
How do I put the "or" part of it in there? I know how to do the or(x,y)
thing in a worksheet.


Just as you wrote it:

If this Or that Then doThis

where "this" and "that" are expression like x<1 and 10<x.

But bewa all expressions are evaluated. So, for example, you might want
to write the following:

If x0 And y/x 10 Then doThis

thinking that the x0 condition protects against a div-by-zero error in
y/x10. It does not! You have to write something like:

If x0 Then
If y/x 10 Then doThis
End If

Similar situations arise with Or, of course.