How to use AND/OR in excel for this? - excel

I am curious as how I can solve this.
I have a column containing product name(columns AQ) and I have created a column to its right showing(column AR) 1 or 0 if it matches.
this is the code :=IF(RIGHT(AQ3;3)="MAX";1;0)
What I wanted to know is... how can I use the AND or OR function to add "BAS"( so it has both "MAX" and "BAS") in the above code?
I tried this but it returned #VALUE.
Failed attempt.IF(RIGHT(AQ3;3)="MAX";1;0);IF(RIGHT(AQ3;3)="BAS";1;0)
Thanks for the answers: How to I use "AND" in this?

You use it as follows:
=IF(OR(RIGHT(AQ3;3)="MAX";RIGHT(AQ3;3)="BAS");1;0)
OR works like that: OR( Expr1 ; Expr2 ; Expr3? ...)
If any of those expressions evaluate to TRUE, then OR returns true.

Your IF syntax will work like this:
=IF(RIGHT(AQ3;3)="MAX";1;IF(RIGHT(AQ3;3)="BAS";1;0))
or an alternative OR version:
=IF(OR(RIGHT(AQ3;3)={"MAX";"BAS"});1;0)

Related

IF, OR and IFERROR function in excel

Column_A Column_B New (Expecting result for this situation)
#N/A #N/A Manual Posting
My function has problem for the last syntax"IFERROR(IFERROR(....)" . Currently, I get #N/A for the "New" column. However, I want to get "Manual Posting" instead.
My syntax:
=IF(OR(IFERROR(B1,A1)="Bank BPH",IFERROR(B1,A1)="GE Budapest Bank"),"GECapital",IF(IFERROR(B1,A1)="Avio Aero","GE Aviation",IFERROR(IFERROR(B1,A1),"Manual Posting")))
Ok, working it out I think I can explain.
IFERROR(x,y) returns value x, unless it's an error, then it returns y .. (even if it is an error).
You then take result of that, and compare it to a string:
IFERROR(A1,B1)="Bank BPH"
Assuming valid values, that expression will, of course, return TRUE or FALSE.
If both A1 and B1 are error, however, what happens ??
What is the result of:
#ERR="string" ??
answer: an error ...
so what does the IF do with an error? it's neither true, nor false.
You can simplify the situation to just this expression to see what's going on:
=IFERROR(A1,B1)="Bank BPH"
it returns an error.
Neither true nor false.
You're going to need another check condition for an error and how to handle it ..
perhaps:
=IF(AND(ISERROR(A1),ISERROR(B1)), "Manual post", IFERROR(A1,B1)="Bank BPH")
might do the trick ??
I think I figure out the correct syntax. I used to put the "AND(ISERROR(B18),ISERROR(A18)),"Manual Posting" to the end. However, I moved it at the beginning, it seems the problem can be solved.
=IF(AND(ISERROR(B18),ISERROR(A18)),"Manual Posting",IF(OR(IFERROR(B18,A18)="Bank BPH",IFERROR(B18,A18)="GE Budapest Bank"),"GE Capital",IF(IFERROR(B18,A18)="Avio Aero","GE Aviation",IFERROR(B18,A18))))

VBA creating a string based on conditions

I need to create a string of the next type:
"<a=1 b=123 c=15 d=19 e=12345>" (rough example)
BUT if any of these variable doesn't exist, it shouldn't be printed at all. Hard to explain, but here is an example.
Desired output: <a=1 c=15 e=12345>
My current output: <a=1 b= c=15 d= e=12345>
I can do this by many case conditions, but is there a more elegant way to do this, ideally in one statement. May be something like (just what I want to find, it's not my expectation code)):
print "<[if a exists]a=" & a & ", [if b exists] b=" & b ...>"
Thanks!
Sounds like the easiest way to do this is using the iif() function. This is more or less what you ask for with [if a exists]. Not sure what condition to test because the information you have given does not make that clear. But I think you should be able to figure it out.

select case with variable boolean operator

This is my first question on the forum, but reading previous questions has been enormously helpful in the project I'm working on, so already my thanks. I couldn't find an answer to this, but apologies if I overlooked something.
I am writing an excel macro in vba, and am trying to create a select case... statement in which the expression has a variable boolean and numeric component. For example, the macro can pull "> 3" or "< 3" from another worksheet.
My hope had been that I could assign to a string all of these parameters, i.e.:
test1 = "is " & BoolOperator1 & " " & NumericValue1
and then
Select case ValuetoCompare
Case test1
'Do something
Case test2
'...
Is there a way to do this? I suppose the alternative would be to nest the case with the numeric variable inside a select function that determines the operator, but I thought this would be more elegant.
Thanks in advance for your guidance--
Josh
Assuming that you'll get a string BoolOperator1 that is a valid operator, e.g. >=, =, and a numeric value NumericValue1, the easiest way to execute this comparison on another numeric value ValueToCompare is to use the Evaluate function. This will execute a string as VBA and return it's result.
In your case, you could simply use:
If Evaluate(ValueToCompare&BoolOperator1&NumericValue1) Then ...
If you want to use this in a Select Case statement, you'd either need to use a simple If ... ElseIf ... statement - or use this trick:
Select Case True
Case Evaluate(ValueToCompare&BoolOperator1&NumericValue1): ...
Case Evaluate(ValueToCompare&BoolOperator2&NumericValue2): ...
Case Else ...
End Select

Comparing two string values with an if statement

I am using excel 2010 and want to give out 1 if it's true and 0 if it's false for a given string.
I tried:
=IF((EXACT(G2;"V") OR EXACT(G2;"K"));"1";"0")
However, this always gives me an error.What's wrong with this formula?
I appreciate your replies!
That's not how you use the OR formula. Try this:
=IF(OR(EXACT(G2;"V");EXACT(G2;"K"));"1";"0")
It is indeed:
OR(Test; Test; Test; ...)
Note:
I'm not sure why you used "1" and "0", but you can drop the quotes if you don't mind having numbers.
You might also simply use:
=OR(EXACT(G2;"V");EXACT(G2;"K"))
To get the result as TRUE or FALSE, or if you want to get 1 or 0...
=OR(EXACT(G2;"V");EXACT(G2;"K"))*1

How to write a compound IF statement checking two sets of two values

I know the title is confusing, but I can't figure our how to word it properly. I'm trying to figure out how to properly format a compound conditional in an IF statement in Excel. It's for a school project that's due tomorrow.
I already have something like this
=if(AND(b152="oval.jpg",c152="q'")OR(AND(b152="triangle.jpg", c153="p'")), "Correct", "Incorrect")
In psuedocode I want it to run something like this:
if (b152=="oval.jpg" && c152=="q'") or (b152=="triangle.jpg", c153="p'"):
print("YES!")
else
print("False!")
I know I'm missing something here. My current excel code returns false even if the conditions are true. Thanks ahead of time!
OR is a function in Excel, like AND. Try something like this:
=if(OR(AND(b152 = "oval.jpg", c152 = "q'"), AND(b152 = "triangle.jpg", c153 = "p'")), "Correct", "Incorrect")

Resources