How should I write an if statement for the folloing: IF 0<X<90 OR 180<X<270 then PRINT B. On the other hand, IF 90<X<180 OR 270<X<360 then PRINT S.

Note that there are two contions for every case. If one of the two conditions in case one satisfies, then the output should B, The same for case two. Additionally, everything should be in one statement. I mean that I do not want to seperate the two cases in two cells.

Thank you in advance.

What happens if X equals0 or 90 or 180 or 270 or 360?

This should get you what you asked for. It will return "" (blank) if A1 equals 0 or 90 or 180 or 270 or 360 or 360>A1<0.

=IF(OR(AND(A1>0,A1<90),AND(A1>180,A1<270)),"PRINT B",IF(OR(AND(A1>90,A1<180),AND(A1>270,A1<360)),"PRINT S",""))

Thank you thank you thank you. It works very very well. Answering your question about the other cases;it should be ignored. I only care if it is greater or smaller than the value.

I'm glad I could help. re:

...about the other cases;it should be ignored...Actually, I don't think that you want them to be

ignored.The formula I offered did not ignore those cases, it dealt with them by returning a blank cell ("") if none of the other conditions were met.

The formula below actually does "ignore" them, by not telling Excel what to return if the other conditions are met.

Try it and I think you'll see why you don't want to "ignore" values outside of your ranges.

See what happens if you use this formula with a 0 in A1.

=IF(OR(AND(A1>0,A1<90),AND(A1>180,A1<270)),"PRINT B",IF(OR(AND(A1>90,A1<180),AND(A1>270,A1<360)),"PRINT S"))

It gave a "FALSE". Do I have to stick with the first formula? I have another question. How to do the following:

If the output is "PRINT S", highlight the cell that has "PRINT S" red.

If the output is "PRINT B", highlight the cell that has "PRINT B" green.Is my question clear?..... Sometimes I feel like I do not know how to say something?

Of course you should stick the first formula - assuming you want a blank cell when your conditions aren't met. I was simply pointing out the you can't "ignore" the other conditions. You have to tell Excel what to do with them, as I did in the first formula. If you "ignore" them, you'll get a FALSE, which I'm sure is not what you want.

As far as Red and Green, look up Conditional Formatting in the Excel Help files and follow those steps. I think Excel 2010 uses the same steps as Excel 2007, but I'm not sure. It should be in the Help files in any case.

If you have trouble, come on back, but please post that question in a new thread.

I will try and see. Thank you again.

Ask Your Question

Weekly Poll

Do you think Jony Ive could make a big impact on Airbnb?

Discuss in The Lounge

Poll History