I am writing a very simple function to calculate pressure drop along a rough pipe, the code is below
From my understand of the way I've written the function, I should be able to execute it by simply writing =pdrop() into any cell in my worksheet.. this is not the case however. If I do this I simply get a #VALUE error, and I know the input data I'm using works because I've tested it independently elsewhere. Any ideas as to what could be the problem?![]()
Function pdrop(ByVal rho As Double, Q As Double, D As Double, mu As Double, TubeL As Integer) Dim Velocity As Double Dim Re As Double rho = Pipecalc.Range("E49").Value D = Pipecalc.Range("J45").Value mu = Pipecalc.Range("E48").Value Q = Pipecalc.Range("E47").Value TubeL = Pipecalc.Range("E45").Value Velocity = 4# * Q / (WorksheetFunction.Pi * D ^ 2) Re = rho * Velocity * D / mu If Re < 2300 Then fricfac = 64 / Re Else fricfac = 0.3164 / Re ^ 0.25 End If pdrop = (Velocity ^ 2 * rho * fricfac * TubeL) / 2# * D End Function
NB: This is the first function I've had to write so if I've done anything stupid don't hesistate to let me know as I need to pick VBA up quite quickly.![]()
Bookmarks