' ****************************************************************
' *** WHEN A VALUE IS CHANGED, THE FOLLOWING CODE IS TRIGGERED ***
' ****************************************************************
Private Sub Worksheet_Change(ByVal Target As Range)
Dim bgcol As Integer
On Error GoTo errhandler:
For Each c In Target
bgcol = c.Interior.ColorIndex
If bgcol = 4 Then ' Standard
If Not c.Value = "" And IsNumeric(c.Value) Then ' Makes sure not null and numeric
Select Case Cells(c.Row, 7)
Case "SF45":
If (c.Value <= 0.764 Or c.Value >= 0.932) Then ' FAIL
'c.Interior.ColorIndex = 3
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Fail"
ElseIf (c.Value > 0.764 And c.Value <= 0.792) Or (c.Value >= 0.904 And c.Value < 0.932) Then ' WARNING
'c.Interior.ColorIndex = 45
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Warning"
Else
Debug.Print Cells(c.Row, 2), "Pass"
End If
Case "SG40":
If (c.Value <= 0.91 Or c.Value >= 1.042) Then ' FAIL
'c.Interior.ColorIndex = 3
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Fail"
ElseIf (c.Value > 0.91 And c.Value <= 0.932) Or (c.Value >= 1.02 And c.Value < 1.042) Then ' WARNING
'c.Interior.ColorIndex = 45
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Warning"
Else
Debug.Print Cells(c.Row, 2), "Pass"
End If
Case "SJ53":
If (c.Value <= 2.493 Or c.Value >= 2.781) Then ' FAIL
'c.Interior.ColorIndex = 3
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Fail"
ElseIf (c.Value > 2.493 And c.Value <= 2.541) Or (c.Value >= 2.733 And c.Value < 2.781) Then ' WARNING
'c.Interior.ColorIndex = 45
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Warning"
Else
Debug.Print Cells(c.Row, 2), "Pass"
End If
Case "SN50":
If (c.Value <= 8.15 Or c.Value >= 9.23) Then ' FAIL
'c.Interior.ColorIndex = 3
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Fail"
ElseIf (c.Value > 8.15 And c.Value <= 8.33) Or (c.Value >= 9.05 And c.Value < 9.23) Then ' WARNING
'c.Interior.ColorIndex = 45
'c.Font.Bold = True
Debug.Print Cells(c.Row, 2), "Warning"
Else
Debug.Print Cells(c.Row, 2), "Pass"
End If
End Select
End If
ElseIf Cells(Target.Row, 50).Interior.ColorIndex = -4142 Then ' Auto bolden
If Cells(Target.Row, 50) >= 1 Then ' If final grade is big
Cells(Target.Row, 50).Font.Bold = True ' Bolden it
Else ' Under 1
Cells(Target.Row, 50).Font.Bold = False ' No boldness
End If
End If
Next c
errhandler:
Exit Sub
End Sub