Excel IF Function woth logical operators - excel

I really don't know why this is not working, I want to create an additional column in excel with the following:
If the value X is lower or equal to 40, then 0, if between 41 and 55, then 1 and if greater 55, then 2.
I thought of this: =IF(x>41,0,IF(41<=x<=55,1,2)), but it does not work as it only gives me 0 and 2, but not 1...
Any idea here?
Thanks in advance!

The syntax for an Excel IF statement is:
IF(condition, value if True, value if False)
You should write your statement like this:
IF(x>55,2,IF(x>40,1,0))

On google sheets I was able to get the desired results with =IF(x>41,IF(x>=55,2,1),0). Your if statements appear to be backwards, and the double comparison statement is probably causing you to get false positives due to a partially true condition

Related

A cell is equal to Multiple numbers present in an IF statement, excel

I have a cell, and in this cell I can cycle through 1 to 15. I need another cell to check if that cell has any of these numbers: 1,3,5,7,9,11,13, and 15. If true, it outputs a 1. I couldn’t find nay examples for my specific problem, and I don’t really understand, so I need some help.
I have looked it up, but couldn’t understand it, and they don’t have g specific problem
=IF(B13=(1,3,5,7,9,11,13,15),1) this won’t work, but I imagine it to be something like this
Since they are all the ODD numbers:
=IF(ISODD(B13),1,0)
If you want specific numbers:
=IF(OR(B13={2,4,6,7}),1,0)
If 1 and 0 are your desired outputs we can remove the IF:
=--OR(B13={2,4,6,7})
Checks if the number is odd (based on the numbers you provided) and is below or equal to 15.
=IF(AND(ISODD(B13),B13<=15),1,0)
Or you could put the numbers you are checking for in a Select Case statement:
Sub CheckCell()
Dim ckNum As Integer
ckNum = Range("E25").Value
Select Case ckNum
Case 1, 3, 5, 7, 9, 11, 13, 15
Range("F25").Value = 1
Case Else
Range("F25").Value = 0
End Select
End Sub
Then you can check for any numbers you want.

Excel Statement with 4 conditions and 4 answers

All of the methods that I've used have 2 answer values (True or False).
How can I get the following with a formula?
If A1=1 then it's 11, if A1=2 the answer is 22, if A1=3 then it's 33, if A1=4 it's 44.
If the value your are evaluating is in cell A1, then the nested function would be as follows:
IF(A1=1,11,IF(A1=2,22,IF(A1=3,33,IF(A1=4,44,""))))
I put the 2 double commas at the end so the formula returns a blank instead of false.
I don't know if that's what you are asking about, but you can make multiple (nested) IF statements in one. For example:
IF(1=2;TRUE;IF(2=2;TRUE;FALSE))
You just put another IF in the FALSE part of IF statement. If that's not it, can you give a piece of the statement you tried and precise more what do you want?
=IF(AND(INT(A1)=A1,A1<=4,A1>=1),A1*11,"")
Now the above works for the condition you placed in your example, however if one were to go by your title alone you have a couple of options you could go with.
You first Option would be nested IF statements. Like you said each IF function has TRUE or FALSE. The trick is to put another IF function in for the TRUE result and another in for the FALSE results
IF(CHECK1, IF(CHECK2, TRUE2, FALSE2),IF(CHECK3, TRUE3, FALSE3))
The above give 4 potential results based on only 3 checks. Another option would be to do a check and supply a value for a TRUE result and another IF for a false result. Keep repeating the process. Conversely you could go the same route flipping TRUE FALSE option. It might look something like this:
IF(CHECK1, TRUE1, IF(CHECK2, TRUE2, IF(CHECK3, TRUE3, FALSE3)))
FALSE3 would be the result of all previous checks failing.
So for your case, your nested IF could look like (assuming the only valid entries are 1, 2, 3 and 4):
IF(A1=1,11,IF(A1,2,22,IF(A1=3,33,44)))
OR
IF(ISODD(A1),IF(A1=1,11,33),IF(A1=2,22,44))
and there are other options to work through the logic. there are also other checks you could be doing and results being displayed if your entries in A1 were not limited to the integers 1,2,3 and 4.
Now because you example is using the sequential integers 1,2,3 and 4 you could also use the CHOOSE function. Alternatively if you can make your criteria evaluate to sequential integers stating at 1 the CHOOSE function would work as well. Supply choose with an integer as the first argument and it will return the corresponding argument in the list that follows
CHOOSE(ARGUMENT,RESULT1, RESULT2,...,RESULTn-1, RESULTn)
In your case it would look something like:
CHOOSE(A1,11,22,33,44)
If you can not get sequential numbers for whatever reason and the gap is numbers is small and you are in the low integer count, you could leave a gap in results by providing "", or 0). lets say you has 1,3 and 4 as potential arguments, then your choose might look like:
CHOOSE(A1,11,"",33,44)
=IF(A1<>"",INDEX({11;22;33;44},A1),"")
=IF(AND(ISNUMBER(A1),A1<=4),A1*11,"")

Conditional IF() statement problem, not returning desired value

Currently writing a program in excel that will return a value based on user input. The current formula has 5 different return options which are returned based on the selection of a number by the user. I use the IF() statement embedded into more IF() statements to account for multiple input options. However, when I go to enter in a number beyond the range of the first IF() statement, I am getting 0 even though it should be a different number.
For the code below, C30 is the input cell and it should return .15 if I was to enter 25.
=IF(C30<20, 0.35, IF(20<C30<40, 0.15, IF(40<C30<60, 0, IF(60<C30<80, -0.1, IF(80<C30, -0.2, 0)))))
From the logic statements, it should be returning .15, but all I am getting is 0.
Excel does not use 20<C30<40 it would be:
AND(20<C30,C30<40)
But you can shorten this with a simple MATCH and CHOOSE:
=CHOOSE(MATCH(C30,{0,20,40,60,80}),0.35,0.15,0,-0.1,-0.2)
If you really want a nested if there is no need for the extra tests:
=IF(C30<20,0.35,IF(C30<40,0.15,IF(C30<60,0,IF(C30<80,-0.1,-0.2))))
IF will resolve sequentially and short circuit as soon as it finds the first TRUE, so it does not need the other logic.
The problem here is the logic that you have used to evaluate whether C30 falls within a range of numbers.
IF(20<C30<40,...) will not check whether C30 is in the range of 20 through 40.
Instead, use AND(cond1, cond2, ...) to check whether the values are within the range:
IF(AND(C30 > 20, C30 < 40), ...)
Replace terms like:
20<C30<40
with:
AND(20<C30,C30<40)
etc.

Having trouble in nested IFs in excel with true or false values in each IF statement

=IF(AND(A2<=20151231),(B2=0) 0, 15, IF(AND(A2>=20190101,B2>=2),15, 7.5))
This is what I entered in the function.
if A2 is less than 20151231 and B2 is equal to 0 the value will be 0.
if A2 is greater than 20190101 and B2 is equal to or greater than 2 the value will be 15.
the problem is that excel says that I entered too many arguments and when I try to derive it it says that there is something wrong with the function I entered.
Try this:
=IF(AND(A2<=20151231,B2=0),"0",IF(AND(A2>=20191010,B2>=2),15,""))
it seems your formula has too much close and open parenthesis. When using "and()" enclose all logic in one set of parenthesis.
Hope this helps. Thanks
Reymond's answer is correct, assuming that you want the result to be:
0 - if A2<=20151231 AND B2=0
15 - if A2>=20190101 AND B2>=2
7.5 - if neither of these cases are true.
If you are struggling to see what parameters you are passing to which function, I would suggest that you format your formulas so that they are easier to read:
=IF(
AND(A2<=20151231, B2=0),
0,
IF(
AND(A2>=20190101,B2>=2),
15,
7.5
)
)
This makes it much easier to see what is going on and it can even be done in the excel formula bar if you wish (by using Alt+Enter):

Excel Nested IF Statement Trouble

=IF(J4 >= 20, A, IF(J4 < 20 AND J4 > 13, B, IF(J4 < 14 AND J4 > 8, C, IF(J4 < 8, D,0))))
The numeric values = points
The values A - D is a scoring systems that rates a person based upon their points and gives them a value from A-D.
I've been stuck on this formula for a long time and have no idea what I'm doing wrong, all help would be appretiated!
Try this:
=IF(J4 >= 20, "A", IF(J4 > 13, "B", IF(J4 > 8, "C", "D")))
Here is a formula:
=IF(20<=J4,"A",IF(13<=J4,"B",IF(8<=J4,"C",IF(J4<8,"D",0))))
You may consider to update your statement as follows.
=IF(J4<8,"D",IF(J4<14,"C",IF(J4<20,"B","A")))
You can see that it's important in this case to move in one direction, either low to high, or high to low. This allows us to return a result whenever a test returns TRUE, because we know that the previous tests have returned FALSE.
I think the syntax you're using for the AND function is wrong. You need to nest all the parameters you want to use within the AND function. like this:
=IF(AND(J4<20,J4>8),"true","false")
Another apporach assuming that the possible inputs in J4 are integers below 1000:
=IFERROR(INDEX({"A";"B";"C";"D"},MATCH(J4,{1000;19;12;7},-1)),0)
I think this one is easier to read and to maintain.

Resources