I'm trying to solve "N Factor" of the following equation in VBA:
I have looked for other similar questions and I can't find any with suitable solutions.
I thought an iterative approach to obtain "N Factor" value from an initial value of N would work in VBA. For reference, the worksheet used is shown below:
When I try to do this programmatically in VBA incrementally from an initial value of N, it doesn't work. My code is below:
Function Fun_N(C, R, E, M, D As Double) As Double
With Application.WorksheetFunction
Dim D_Cal As Double
N = 0.001 'Arbitrary number to initialize the loop
D_Cal = ((1.5 * C) / ((4 * Atn(1)) * R)) * ((((0.0045 * E) ^ 3) / (N ^ 3)) * (1 - (1 / ((1 + (E / R) ^ 2) ^ 0.5))) + (1 / (M * ((1 + ((40000 * (N ^ 2)) / ((R ^ 2) * ((M) ^ (2 / 3))))) ^ 0.5)))) 'Constant Pi = 4 * Atn(1)
While D_Cal < D
N = N + 0.000001
D_Cal = ((1.5 * C) / ((4 * Atn(1)) * R)) * ((((0.0045 * E) ^ 3) / (N ^ 3)) * (1 - (1 / ((1 + (E / R) ^ 2) ^ 0.5))) + (1 / (M * ((1 + ((40000 * (N ^ 2)) / ((R ^ 2) * ((M) ^ (2 / 3))))) ^ 0.5)))) 'Constant Pi = 4 * Atn(1)
Wend
End With
Fun_N = N
End Function
I'm not know the issue (code, loop...)
Thanks in advance for help.