Function CalculateOER(xx As Range, yy As Range) As Variant
    Dim G_ooh_0 As Double
    Dim G_o_0 As Double
    Dim G_oh_0 As Double
    Dim lim_oer_1 As Double
    Dim lim_oer_2 As Double
    Dim lim_oer_3 As Double
    Dim lim_oer_4 As Double
    Dim oer_lim As Double
    
    G_ooh_0 = yy.Value - 3 * 1.23
    G_o_0 = 2 * xx.Value - 2 * 1.23
    G_oh_0 = xx.Value - 1.23
    
    lim_oer_1 = 0 - G_ooh_0
    lim_oer_2 = G_ooh_0 - G_o_0
    lim_oer_3 = G_o_0 - G_oh_0
    lim_oer_4 = G_oh_0 - 0
    
    oer_lim = Application.WorksheetFunction.Max(lim_oer_1, lim_oer_2, lim_oer_3, lim_oer_4)
    
    CalculateOER = oer_lim
End Function

Function CalculateORR(xx As Range, yy As Range) As Variant
    Dim G_ooh_0 As Double
    Dim G_o_0 As Double
    Dim G_oh_0 As Double
    Dim lim_orr_1 As Double
    Dim lim_orr_2 As Double
    Dim lim_orr_3 As Double
    Dim lim_orr_4 As Double
    Dim orr_lim As Double
    
    G_ooh_0 = yy.Value - 3 * 1.23
    G_o_0 = 2 * xx.Value - 2 * 1.23
    G_oh_0 = xx.Value - 1.23
    
    lim_orr_1 = G_ooh_0 - 0
    lim_orr_2 = G_o_0 - G_ooh_0
    lim_orr_3 = G_oh_0 - G_o_0
    lim_orr_4 = 0 - G_oh_0
    
    orr_lim = Application.WorksheetFunction.Max(lim_orr_1, lim_orr_2, lim_orr_3, lim_orr_4)
    
    CalculateORR = orr_lim
End Function

Function CalculateDeltaDeltaE(xx As Range, yy As Range) As Variant
    Dim Delta_E1 As Double
    Dim Delta_E2 As Double
    
    Delta_E1 = 57.939 * xx.Value
    Delta_E2 = 57.939 * yy.Value
            
    CalculateDeltaDeltaE = Abs(Delta_E2 - Delta_E1)
End Function

Function DeltaE_OH(xx As Range) As Variant
    Dim invr As Double
    
    invr = xx.Value
            
    DeltaE_OH = 4.4695 * invr + 1.0139
End Function

Function DeltaE_O_OH(xx As Range) As Variant
    Dim invr As Double
    
    invr = xx.Value
            
    DeltaE_O_OH = 13.51 * invr + 3.6588
End Function

Function DistanceToLine(yy As Range, xx As Range) As Double
    Dim m As Double
    Dim b As Double
    m = -0.2216
    b = 0.617
    
    Dim x As Double
    Dim y As Double
    x = xx.Value
    y = yy.Value
    
    
    DistanceToLine = Abs(y - (m * x + b)) / Sqr(m ^ 2 + 1)
End Function

