Excel OR IF statement - excel

I have a drop down with three different choices. I'm trying to make the below cell have a question depending which drop down selection you choose. so far it works with one statement
=IF($B$2="A","First","").
That works, but when i add an or statement it does not work
=IF($B$2="A","First","") OR IF$B$2="B","Second","")
This does not work how can i change this so i cave this statement work for three choices with the formula in one cell.

=IF($B$2="A","First", IF($B$2="B", "Second", IF($B$2="C", "Third","???")))
or
=IFERROR(VLOOKUP(B3,{"A","First";"B","Second";"C","Third"},2,FALSE),"???")

You cannot use OR function in Excel that way. Have a look at this: https://exceljet.net/excel-functions/excel-or-function
You could trying using nested IF statements OR you could use some other method (like a VLOOKUP)
Nested If would be something like this:
=IF($B$2='A', 'First', IF($B$2='B', "Second", ""))

The "nested ifs" is your best option.
=IF($B$2="A","First","")
=if($B$2=A,"condition 1","condition 2")
Condition 1 is true, i.e. $B$2=A
Condition 2 is false, i.e. $B$2 does not equal <> A
The way to nest the ifs is to include it instead of "condition 1" or "condition 2".
So =if($B$2=A,if($B$2=B,"condition 2", "condition 3"),"condition 1")
$B$2=A and $B$2=B are both true then condition 2
$B$2=A is true but $B$2=B is not true then condition 3
$B$2=A is not true then condition 1
This is the logic behind nested ifs. You can expand this.

Related

OR Formula in Word document not returning a value

I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}

Multiple nested If statement - And Or not working

Using a nested If Statement in Excel I have been trying to obtain results using the following criteria:
within 100 and 75000 Volts but should accept 11; 22; 25; 26; 30; 33; 66
as they will be in kV
Source data is in a table Transformers and the formula is also returning data on two other tables MASTER and META.
I have tried in vain all kinds of IF/AND/OR variants of the following, however I have rarely used nested if statements before so am not at home with the logic. Any help gratefully received !
Thank you
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2"), IF(OR(Transformers!T2>=110, Transformers!T2<=75000) OR(Transformers!T2=11, Transformers!T2=22, Transformers!T2=25, Transformers!T2=26, Transformers!T2=30, Transformers!T2=33, Transformers!T2=66),"Failed Check 3","Passed Check 3"))
Thank you
It looks like you need an AND as the first term in your OR. The parenthesis also looked incorrect. Once the complexity reaches a certain stage it sometimes helps to compose the formulas in something like Notepad with white-space to display the logic:
=IF(MASTER!N2="Failed Check 1",
"Failed Check 1",
IF(META!N2="Failed Check 2",
"Failed Check 2",
IF(OR(
AND(Transformers!T2>=110, Transformers!T2<=75000),
Transformers!T2=11,
Transformers!T2=22,
Transformers!T2=25,
Transformers!T2=26,
Transformers!T2=30,
Transformers!T2=33,
Transformers!T2=66
),
"Failed Check 3",
"Passed Check 3"
)
)
)
Without linebreaks this is:
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2", IF(OR(AND(Transformers!T2>=110, Transformers!T2<=75000),Transformers!T2=11, Transformers!T2=22, Transformers!T2=25, Transformers!T2=26, Transformers!T2=30, Transformers!T2=33, Transformers!T2=66),"Failed Check 3","Passed Check 3")))
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2", IF(OR(Transformers!T2>=110, Transformers!T2<=75000, Transformers!T2=11, Transformers!T2=22, Transformers!T2=25, Transformers!T2=26, Transformers!T2=30, Transformers!T2=33, Transformers!T2=66),"Failed Check 3","Passed Check 3")))
Some problems in your formula:
before the second OR a comma is missing, it should be ),OR(
closing parenthesis of first OR is missing, it should be ...=66)),...
closing parenthesis of IF is missing, your formula should end to )))
+1 you are looking for values between 100 and 75000, this could be done with AND instead of OR
Another approach
To simplify your formula you can place your valid kV values in a range and refer to it; let's call it kVolts (one value per cell, either in one row or in one column)
The simplified formula:
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2"), IF(OR(AND(Transformers!T2>=110, Transformers!T2<=75000),IFERROR(MATCH(Transformers!T2,kVolts,0)>0,FALSE)) ,"Failed Check 3","Passed Check 3")))
Based on your conditions, I would recommend you implement this one liner which assumes your data is in cell A1.
=IF(OR(AND(A1>=100,A1<=75000),A1=11,A1=22,A1=25,A1=26,A1=30,A1=33,A1=66),TRUE,FALSE)
Although this only returns TRUE or FALSE, which doesn't tell you which check it has passed.

Nested IF statement returning false

I have a nested if statement is returning "False" rather than the expected outcome.
Scenario
Table "High VoltageCables" has data in it that default to numeric but may contain characters: kVa
Table "Master" checks "High VoltageCables" data as blank or not blank, and returns "Failed Check 1","Passed Check 1". This works fine.
Table "Meta" then checks the results of "Master" and then tests "High VoltageCables" data for length between 1 and 6, regardless of whether record is numeric or string.
Formula
=IF(MASTER!H2="Passed Check 1",IF(LEN('High VoltageCables'!O2)>=1,IF(LEN('High VoltageCables'!O2<6),"Passed Check 2","Failed Check 2")))
This is partially succesful, as it returns "Passed Check 2" for the following sample data in the source table "High VoltageCables".
1 numeric, or
1kVa str, or
50000 numeric
However if a field in "High VoltageCables"is blank, the formula returns "FALSE" rather than "Failed Check 1"
I inherited this task, (and would have preferred to do the whole thing in Access using relatively simple queries) - and unfortunately I am new to nested If statements, so I am probably missing something basic...
NB the data in High VoltageCables must default to numeric for a further check to work.
The first and second IF's seem to be missing the else part. They should be added at the end between the ))) like ), else ), else )
Every IF statement consists of IF( condition, truepart, falsepart) if you have two nested ifs it will be something like IF( condition, IF( condition2, truepart2, falsepart2), falsepart)
Hope that makes it a little clearer
You do have an unaccounted for FALSE in the middle IF. Try bring the latter two conditions together.
=IF(Master!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"))
It's still a bit unclear on what to show or not show if Master!H2 does not equal "Passed Check 1".
I failed to construct the formula with a concluding "else" - "Failed Check 1"
Using jeeped's and Tom's suggestion and adding the final "else" part I have solved the problem:
=IF(MASTER!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"),"Failed Check 1")

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

Resources