User Defined Formula (UDF) Problem - Results is either 0 or #value error

Capitan

New Member
Joined
Jul 31, 2018
Messages
4
Hi,

I'm new to VBA so please bear with me.

I'm trying to create a UDF function that will calculation turbulent friction faction using churchill equation
The arguments include reynolds number, absolute roughness (mm), internal diameter (mm).
I've followed several tutorials in formulating the following code but the only results i get is either 0 or a #value error.

Code:
Public Function turbulentFrictonFactor(reynoldsNumber As Double, absoluteRoughness As Double, internalDiameter As Double) As Double


'Constants declaration
Dim constB As Double
Dim constC As Double
Dim denominator1 As Double
Dim denominator2 As Double
Dim denominatorSum As Double
Dim item1 As Double
Dim item2 As Double


'Calculation of constB
denominator1 = (7 / reynoldsNumber) ^ 0.9
denominator2 = 0.27 * (absoluteRoughness / internalDiameter)
denominatorSum = denominator1 + denominator2


constB = (2.457 * Log(1 / denominatorSum)) ^ 16


'Calculation of constC


constC = (37530 / reynoldsNumber) ^ 16


'Calculation of turbulent friction factor.
'where item1 = (8/Re)^12
'where item2 = 1/(B+C)^1.5


item1 = (8 / reynoldsNumber) ^ 12
item2 = 1 / (constB + constC) ^ 1.5


turbulentFrictionFactor = 8 * (item1 + item2) ^ 1 / 12


End Function

I would appreciate if someone can point out where i am going wrong?
Thanks in advance
 
Apologies, I agree, I shouldn't have hijacked the thread just because I write in a different style
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Far as i can see the only difference between the UDF calc and the formula calc is this line:

Code:
turbulentFrictionFactor = 8 * (item1 + item2) ^ 1 / 12

which should be:

Code:
turbulentFrictionFactor = 8 * (item1 + item2) ^ (1 / 12)


This correction solved my problem. I still made a mistake despite my efforts to break down the equation into simple chunks.

Many thanks all
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top