I'm tring to make Satayanaga's best fit equation for unimodal 2017 to VBA, because I keep having problem with Excel's solver if I put the equation straight to the cell.

I'm trying with this. But I'm not sure if it's right, because it such a complicated one for me. It'll be great if someone can confirm this or give a suggestion.
Function Satyanaga(psi As Double, theta_s As Double, theta_r As Double, _
psi_a As Double, psi_m As Double, s As Double, psi_r As Double) As Double
Dim beta As Double
Dim term1 As Double, term2 As Double
Dim erfcPart As Double
Dim insideLog1 As Double, insideLog2 As Double
' --- Define ß ---
If psi <= psi_a Then
beta = 0
Else
beta = 1
End If
' --- Check log arguments ---
insideLog1 = 1 + psi / psi_r
insideLog2 = 1 + (10 ^ 6) / psi_r
If insideLog1 <= 0 Or insideLog2 <= 0 Then
Satyanaga = CVErr(xlErrNum) ' return #NUM! error in Excel
Exit Function
End If
' --- First log fraction (always between 0 and 1) ---
term1 = 1 - (Log(insideLog1) / Log(insideLog2))
' --- ERFC part ---
If (psi_a - psi_m) = 0 Then
erfcPart = 0
Else
On Error Resume Next
erfcPart = Application.WorksheetFunction.ErfC(Log((psi_a - psi) / (psi_a - psi_m)) / s)
If Err.Number <> 0 Then
Satyanaga = CVErr(xlErrNum)
Exit Function
End If
On Error GoTo 0
End If
' --- Second bracket ---
term2 = theta_r + (theta_s - theta_r) * (1 - beta * erfcPart)
' --- Final result ---
Satyanaga = term1 * term2
End Function
erfcto blend in the more complex behaviour looks to me like an engineering hack rather than a physical equation. BTW when beta=0 the equation simplifies a lot and you should avoid evaluating the nasty complicated termLog((psi_a-psi)/(psi_a-psi_m))(which is guaranteed to fail if it evaluates correctly whenpsi>psi_a). When debugging avoidon error resume nextit makes code behaviour hard to understand.