I am trying to write a statement that does the following:
If R7 = "Yes" AND S7 = "Yes" AND T7 = "Yes", then output 1
If R7 = "Yes" AND S7 = "Yes" AND T7 = "No", then output 2
If R7 = "Yes" AND S7 = "No" AND T7 = "Yes", then output 3
If R7 = "Yes" AND S7 = "No" AND T7 = "No", then output 4
IF anything else, then output 5
I have written the following statement:
=IF(R7="Yes",IF(S7="Yes",IF(T7="Yes",1),IF(R7="Yes",IF(S7="Yes",IF(T7="No",2),IF(R7="Yes",IF(S7="No",IF(T7="Yes",3),IF(R7="Yes",IF(S7="No",IF(T7="No",4)))))))),5)
I know I am close however, issue is when it should display 4, it just displays “FALSE” - have I got my brackets in the wrong order?
Any suggestions?
There's no need to nest so many IF statements, you can use the AND function.
=IF(AND(R7="Yes",S7="Yes",T7="Yes"),1,IF(AND(R7="Yes",S7="Yes",T7="No"),2,IF(AND(R7="Yes",S7="No",T7="Yes"),3,IF(AND(R7="Yes",S7="No",T7="No"),4,5))))
This should work for you.
For further reading, see the office documentation.
You need to construct your formula as follows ...
=IF(AND(R7="Yes",S7="Yes",T7="Yes"),1,(IF(AND(R7="Yes",S7="Yes",T7="No"),2,IF(AND(R7="Yes",S7="No",T7="Yes"),3,IF(AND(R7="Yes",S7="No",T7="No"),4,5)))))
Note that this function returns 5 when there is no matching combination ...
Related
I would like to make an IF statement in Excel where if a certain cell equals to O, V, G or U another cell outputs 1, 2, 3 or 4 respectively.
I can't find any solution only, sorry.
There's probably a cleaner way to do this... but I'm not an excel expert.
If A1 is the cell you are checking to contain O V G or U:
=IF(A1="O", 1, IF(A1="V", 2, IF(A1="G", 3, IF(A1="U", 4, ""))))
The syntax of excel's if is: If(condition, valueIfConditionIsTrue, valueIfConditionIsFalse)
This is how excel interprets the command in a way that's easier for us to understand:
if A1 == "O":
output = 1
else:
if A1 == "V":
output = 2
else:
if A1 == "G":
output = 3
else:
if A1 == "U":
output = 4
else:
output = ""
I think the easiest solution would be to create a look up table and then use a combination of the INDEX MATCH functions to grab the appropriate value. You can read more about INDEX MATCH here: https://exceljet.net/index-and-match
To start, create a table similar to this:
Then assuming you have a list of letters you are trying to match you can write a formula similar to this: =INDEX(Table1[Output],MATCH(E3,Table1[Letter],0)). If you want the formula to return blanks "" instead of #N/A, you can wrap the formula in an IFERROR:
=IFERROR(
INDEX(Table1[Output],MATCH(E3,Table1[Letter],0))
,"")
Here's a picture of the final output.
I have a #value error when trying to nest multiple IF(OR(AND statements.It works with 1 statement but when I nest them I get the value error.
What I am trying to say is:
IF (C7=True) AND 1 of the $A$6 = TRUE (either 11 OR 12) then show text1,
IF (C7=True AND 1 of the $A$6=True (either 6.7,8 OR 9)then show text2,
when both false
IF(C7=TRUE, then "text3", otherwise "-")
=IF(OR(AND(C7=TRUE,$A$6=11),AND(C7=TRUE,$A$6=12)),"Text1"),
IF(OR(AND(C7=TRUE,$A$6=6),AND(C7=TRUE,$A$6=7),AND(C7=TRUE,$A$6=8),AND(C7=TRUE,$A$6=9)),"Text2", IF(C7=TRUE,"Text3", "-"))
The issue with your equation is that you open with IF(OR(AND)) when you want to open with IF(AND(OR)). However, since you want C7 = TRUE for Text1, Text2, Text3 you can nest those inside like so IF(C7 = TRUE, Evaluate A6, "Other").
Then, you just need to Evaluate A6 using OR instead of continuously checking the value of C7
=IF(C7=TRUE,IF(OR(A6=11,A6=12),"Text1",IF(OR(A6=6,A6=7,A6=8,A6=9),"Text2","Text3")),"Other")
I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!
You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.
I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture
I am trying to write a formula and getting error. The logic is:
If A1 > 0 and B1 = "PEN" Output = "Refund 1"
If A1 > 0 and B1 = "INT" Output = "Refund 1"
If A1 > 0 and B1 = "ADM" Output = "Refund 1"
If A1 > 0 and B1 = "AB" Output = "Refund 2"
If A1 < 0 and B1 = "PEN" Output = "Fund 1"
If A1 < 0 and B1 = "INT" Output = "Fund 1"
If A1 < 0 and B1 = "ADM" Output = "Fund 1"
If A1 < 0 and B1 = "AB" Output = "Fund 2"
I am getting errors writing multiples If-statements.
Can someone help?
This will work for you.
=IF(AND(A1>0,OR(B1="PEN",B1="INT",B1="ADM")),"Refund 1",IF(AND(A1>0,B1="AB"),"Refund 2",IF(AND(A1<0,OR(B1="PEN",B1="INT",B1="ADM")),"Fund 1",IF(AND(A1<0,B1="AB"),"Fund 2"))))
While #Jeanno's answer works for this case, I wanted to point out that you can accomplish the same thing more generally using a lookup table.
Items in blue are hard-coded, black are formulas.
There are a couple advantages to doing it this way:
Extensible: if your criteria suddenly grew from testing two conditions to 3 or more, the IF style statement is going to go from almost illegible to completely illegible.
Clear: By looking up the value on a table, anyone can tell why a row is getting assigned to the result. Trying to do that with Excel's nested AND, OR, IF statements is really hard.
I am trying to create a spreadsheet which automagically gives a grade to a student based on their marks they got.
I've apparently hit Excel's nested IF statement limit which is 7.
Here's my if statement:
=IF(O5>0.895,"A+",IF(O5>0.845,"A",IF(O5>0.795,"A-",IF(O5>0.745,"B+",IF(O5>0.695,"B",IF(O5>0.645,"B-",IF(O5>0.595,"C+",IF(O5>0.545,"C","D"))))))))
I was reading online that I could create a VBA script and assign it that, but I dont know anything about VBA....so if someone could help me write a VBA for this, would be awesome.
Its still missing the C- grade and anything lower should be awarded a D mark.
This is the grading scheme I am trying to create...:
A+ 89.500 - 100.000 Pass with Distinction
A 84.500 - 89.490 Pass with Distinction
A- 79.500 - 84.490 Pass with Distinction
B+ 74.500 - 79.490 Pass with Merit
B 69.500 - 74.490 Pass with Merit
B- 64.500 - 69.490 Pass with Merit
C+ 59.500 - 64.490 Pass
C 54.500 - 59.490 Pass
C- 49.500 - 54.490 Pass
D 0.000 - 49.490 Specified Fail
I wouldn't mind going down the VBA route, however my understanding of VB language is absolutely minimal (don't like it)...if this gets too tedious, I was thinking to create a small php/mysql application instead.
You can do this much more elegantly with the VLOOKUP formula by making separate table mapping lower bounds to letters. The mapping table must be sorted by grade number ascending.
For example:
Table
A B
0 D
49.5 C-
54 C
59.5 C+
... ...
Formula:
=VLOOKUP(SomeCell, $A$1:$B$9, 2, TRUE)
Where $A$1:$B$9 is the range with the grade table. (The $ signs tell Excel not to move the reference if you copy the formula).
Passing TRUE as the last argument will cause Excel to do a binary search to find the value, which (as long as the data is sorted) is exactly what you want it to do.
Go to the Visual Basic Editor, and insert this code. I don't know what version of Excel you're using, but for versions before 2007, go to tools, Macros, Visual Basic Editor. For Version 2007 and newer , it is on the Development Tab which is not enabled by default.
Depending on how you want to link it, you could add a button to the page, or call it from the Worksheet_Calculate event.
This assumes that you have the student's total grade in cell A2, and will put the results in A2 and B2.
Sub Calculate
dim LetterGrade as string
dim Superlative as string
Select Case Cells(1,2)
Case >= 89.500
LetterGrade="A+"
Superlative ="Pass with Distinction"
Case 84.500 to 89.490
LetterGrade="A"
Superlative ="Pass with Distinction"
Case 79.500 to 84.490
LetterGrade="A-"
Superlative ="Pass with Distinction"
Case 74.500 to 79.490
LetterGrade="B+"
Superlative ="Pass with Merit"
Case 69.500 to 74.490
LetterGrade="B"
Superlative ="Pass with Merit"
Case 64.500 to 69.490
LetterGrade="B-"
Superlative ="Pass with Merit"
case 59.500 to 64.490
LetterGrade="C+"
Superlative ="Pass"
Case 54.500 to 59.490
LetterGrade="C"
Superlative ="Pass"
Case 49.500 to 54.490
LetterGrade="C-"
Superlative ="Pass"
Case <= 49.490
LetterGrade="F"
Superlative ="Specified Fail"
End Select
Cells(2, 1) = LetterGrade
Cells(2, 2) = Superlative
End Sub
An easy solution would be to simply split the formula into two cells
=IF(O5>0.895,"A+",IF(O5>0.845,"A",IF(O5>0.795,"A-",<Other cell ref here>)))
Other cell:
=IF(O5>0.745,"B+",IF(O5>0.695,"B",IF(O5>0.645,"B-",IF(O5>0.595,"C+",IF(O5>0.545,"C","D")))))
While I prefer the Vlookup method (Slaks solution) for numeric parameters for the simplicity and elegance, an alternative which becomes valuable in case of non-numeric parameters is concatenated IFs.
=IF( Case1 , "Label 1", "" ) &
IF( Case2 , "Label 2", "" ) &
IF( Case3 , "Label 3", "" ) &
..... and so on
For example, in this case:
= IF( O5 >= 89.5 , "A+" , "" ) &
If( AND ( O5 < 89.5 , O5 >= 84.5 ) , "A" , "" ) &
If( AND ( O5 < 84.5 , O5 >= 79.5 ) , "B+" , "" ) &
..... and so on for other levels.
The VLOOKUP solution seems the best. To add a VBA script, you could bring up the Visual Basic Toolbar, add a control like a Button and then double-click it. The code for that event opens in the Excel VBA environment. There you could add the code in VB, perhaps something like this.
Private Sub CommandButton1_Click()
Cells(1, 2) = getValue(Cells(1, 1))
End Sub
Private Function getValue(ByVal argMarks As Double)
If argMarks > 89.5 And argMarks <= 100 Then
getValue = "A+"
If argMarks > 84.5 And argMarks <= 89.49 Then
getValue = "A"
.
.
and so on...
End Function