ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Having "Or" in an If statement doesn't work? (https://www.excelbanter.com/excel-discussion-misc-queries/146633-having-if-statement-doesnt-work.html)

J@Y

Having "Or" in an If statement doesn't work?
 
I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?

PCLIVE

Having "Or" in an If statement doesn't work?
 
One way:

=IF(OR(A2=2,B2=2),TRUE,FALSE)

HTH,
Paul


"J@Y" wrote in message
...
I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?




Mark Lincoln

Having "Or" in an If statement doesn't work?
 
On Jun 15, 11:13 am, J@Y wrote:
I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?


It will work in VBA, but not in a cell formula. In a cell the format
is:

=IF(OR(A=2,B=2),[do if true],[do if false])

Mark Lincoln


ShaneDevenshire

Having "Or" in an If statement doesn't work?
 
Hi,

It's not clear from your question whether you are doing this in the
spreadsheet or in code.

IF in code:

IF a=2 OR b=2 then
...
End IF

or

IF a=2 XOR b=2 then
....
End IF

In the spreadsheet there is no XOR option you would need to make a more
complicated formula.

--
Cheers,
Shane Devenshire


"J@Y" wrote:

I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?



All times are GMT +1. The time now is 03:24 PM.

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