Making IF Statement combining AND and OR

misk0048

New Member
Joined
Jul 10, 2014
Messages
5
Hello,

I'm trying to make an if statement where if one cell equals "BZ" and another cell doesn't equal one of several values then a 1 is displayed.

My current attempt is not working: =IF(OR(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950",LEFT($O2,4)<>"0740",AND(AB$1=$Q2)),1,"")

Any ideas?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I think that should all be a single AND.

Consider this example
OR(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950")
That will ALWAYS be TRUE. No matter what value you have in O2 (except an error value like #N/A)
If LEFT($O2,4) DOES happen to be 0940, then LEFT($O2,4)<>"0950" is TRUE, so the OR is TRUE.
If LEFT($O2,4) DOES happen to be 0950, then LEFT($O2,4)<>"0940" is TRUE, so the OR is TRUE.

Try
=IF(AND(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950",LEFT($O2,4)<>"0740",AB$1=$Q2),1,"")
 
Upvote 0
try
=(AND(OR(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950",LEFT($O2,4)<>"0740"),AB$1=$Q2))+0
 
Upvote 0
I think that should all be a single AND.

Consider this example
OR(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950")
That will ALWAYS be TRUE. No matter what value you have in O2 (except an error value like #N/A)
If LEFT($O2,4) DOES happen to be 0940, then LEFT($O2,4)<>"0950" is TRUE, so the OR is TRUE.
If LEFT($O2,4) DOES happen to be 0950, then LEFT($O2,4)<>"0940" is TRUE, so the OR is TRUE.

Try
=IF(AND(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950",LEFT($O2,4)<>"0740",AB$1=$Q2),1,"")

Doh! Good spot!!

WBD
 
Upvote 0
Thanks WBD for your reply.

For some reason your formula is still giving me a 1 for cells that have BZ and those values. I have rechecked the cells the formulas are referring to and the one says BZ and the other does start with those values (eg: 0950) so I'm not sure where/why the formula is failing.
 
Upvote 0
Awesome, this appears to work! Many thanks!

I think that should all be a single AND.

Consider this example
OR(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950")
That will ALWAYS be TRUE. No matter what value you have in O2 (except an error value like #N/A)
If LEFT($O2,4) DOES happen to be 0940, then LEFT($O2,4)<>"0950" is TRUE, so the OR is TRUE.
If LEFT($O2,4) DOES happen to be 0950, then LEFT($O2,4)<>"0940" is TRUE, so the OR is TRUE.

Try
=IF(AND(LEFT($O2,4)<>"0940",LEFT($O2,4)<>"0950",LEFT($O2,4)<>"0740",AB$1=$Q2),1,"")
 
Upvote 0
You're wecome.

You can use a little shortcut on that AND

=IF(AND(LEFT($O2,4)<>{"0940","0950","0740"},AB$1=$Q2),1,"")
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top