I'm not very good with nested formulas when there are a lot levels and would appreciate some help from an expert.
How would I convert the following blocks of VBA code into nested IF formulas? There are two variations shown below that I am seeking solutions for. For each variation, my goal is to replace all of the code with a formula I can place in cell K4. My data starts off on row 4, but I want to be able to copy the formula down column K to the end of my data set, however, the cell reference on Sheet 2 is fixed and should not change.
1. The code first determines the value (letter grade) of cell C4 of the "Sheet 1" worksheet. It then performs three different logic tests to determine if a "Pass" or "Fail" result should be returned. A "Pass" only results if ALL three tests are passed, otherwise a "Fail" results.
I know the code is horrendous, but I wrote it out quickly in the form of nested If-Then-Else statements with the hope that it may be easier for someone to convert into a nested =IF formula.
2. The second block of VBA code is slightly more complicated as it contains an OR function. There is an AND function that binds the first two tests but an OR function for the third test. Once again, the Sheet 2 cell reference is fixed and should not change.
How would I convert the following blocks of VBA code into nested IF formulas? There are two variations shown below that I am seeking solutions for. For each variation, my goal is to replace all of the code with a formula I can place in cell K4. My data starts off on row 4, but I want to be able to copy the formula down column K to the end of my data set, however, the cell reference on Sheet 2 is fixed and should not change.
1. The code first determines the value (letter grade) of cell C4 of the "Sheet 1" worksheet. It then performs three different logic tests to determine if a "Pass" or "Fail" result should be returned. A "Pass" only results if ALL three tests are passed, otherwise a "Fail" results.
I know the code is horrendous, but I wrote it out quickly in the form of nested If-Then-Else statements with the hope that it may be easier for someone to convert into a nested =IF formula.
Code:
If Worksheet("Sheet 1").Range("C4") = "A" then
[INDENT]If Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") And Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4") And Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B208") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") ="Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "B" then
[INDENT]If Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") And Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4") And Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B209") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "C" then
[INDENT]If Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") And Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4") And Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B210") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "D" then
[INDENT]If Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") And Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4") And Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B211") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "F" then
[INDENT]If Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") And Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4") And Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B212") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]End If
2. The second block of VBA code is slightly more complicated as it contains an OR function. There is an AND function that binds the first two tests but an OR function for the third test. Once again, the Sheet 2 cell reference is fixed and should not change.
Code:
If Worksheet("Sheet 1").Range("C4") = "A" then
[INDENT]If (Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") AND (Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4")) OR Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B208") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "B" then
[INDENT]If (Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") AND (Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4")) OR Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B209") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "C" then
[INDENT]If (Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") AND (Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4")) OR Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B210") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "D" then
[INDENT]If (Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") AND (Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4")) OR Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B211") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]Elseif Worksheet("Sheet 1").Range("C4") = "F" then
[INDENT]If (Worksheet("Sheet 1").Range ("J4") <= Worksheet("Sheet 1").Range ("M4") AND (Worksheet("Sheet 1").Range("J4") >= Worksheet("Sheet 1").Range("L4")) OR Worksheet("Sheet 1").Range("P4") < = Worksheet("Sheet 2").Range("B212") Then
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Pass"
[/INDENT]Else
[INDENT]Worksheet("Sheet 1").Range ("K4") = "Fail"
[/INDENT]End If
[/INDENT]End If