Nested IF statements in Excel [Over the 7 allowed limit] Nested IF statements in Excel [Over the 7 allowed limit] vba vba

Nested IF statements in Excel [Over the 7 allowed limit]


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     B0     D49.5  C-54    C59.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) = SuperlativeEnd 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")))))