ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA IF THEN with an OR (https://www.excelbanter.com/excel-programming/440886-vba-if-then.html)

Papa Jonah

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

Gary Brown[_6_]

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


ryguy7272

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


Mike H

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


Sheeloo

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


Rick Rothstein

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



Joe User[_2_]

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.


Papa Jonah

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



All times are GMT +1. The time now is 12:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com