Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default VBA IF THEN with an OR

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.
Thanks,
Papa J
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default VBA IF THEN with an OR

=if(or(a1=1,a2=10),"Yes","NO")
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"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.
Thanks,
Papa J

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default VBA IF THEN with an OR

This link seems pretty decent:
http://www.experiglot.com/2006/12/11...th-and-or-not/

Look at this example:
=IF(OR(B6<$B$2,B6=$B$3),€¯No bonus€¯, B6*$B$1)
(it's a few clicks down the page...)

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"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.
Thanks,
Papa J

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default VBA IF THEN with an OR

Hi

If x = 1 Or y = 2 Then
'do something
Else
'do something else
End If


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"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.
Thanks,
Papa J

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 793
Default VBA IF THEN with an OR

IF (cond1 OR Cond2) Then
....
Else
....
End If

eg.

Sub test()
If ((Range("a20") = 10)) Or (Range("B20") = 5) Then
MsgBox "Either A20 is 10 or B20 is 5"
Else
MsgBox "both are false"
End If
End Sub
"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.
Thanks,
Papa J



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default VBA IF THEN with an OR

In the worksheet world, OR is a function (hence, the arguments enclosed
within its parentheses); however, in the VB world, Or (along with And, Xor
and a couple of others) are operators just like =, <, =, etc. are and, as
such, it goes between the "operands" it is being used with. So, it would be
used like this...

If Condition1 Or Condition2 Then

--
Rick (MVP - Excel)



"Papa Jonah" wrote in message
...
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.
Thanks,
Papa J


  #7   Report Post  
Posted to microsoft.public.excel.programming
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.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default VBA IF THEN with an OR

Thanks again Mike

"Mike H" wrote:

Hi

If x = 1 Or y = 2 Then
'do something
Else
'do something else
End If


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"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.
Thanks,
Papa J

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



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