UDF inside UDF??

ShelleyBelly

New Member
Joined
Mar 2, 2011
Messages
44
Hi There,

Not sure if i'm asking the impossible but think i might just be.

i'm making a UDF and the algebra requires going to the Nth term, so instead of writing the same section of the formula over again i've written the architecture of it and then incorporated that as a UDF inside the former.

My question is, as the second UDF will only be used in conjunction with the first, is it possible to write it inside the first UDF.

Sorry for the poor explanation. Basically can you put a function inside another as below, or must they be separate??


Cheers



Function MP(Lat1)

'a = 6378137 ' Part of the WGS-84
'b = 6356752.3142 ' ellipsiod datum
f = 1 / 298.257223563

Lat1 = Radians(Lat1)

a = 21600 / (2 * Pi)
e = (2 * f - f ^ 2) ^ 0.5

Function Nth(n, Lat1)

Nth = e ^ (n + 1) / n * Sin(Lat1) ^ n

End Function


MP = a * Log(10) * Log10(Tan(Radians(45) + Lat1 / 2)) - a * (Nth(1, Lat1) + Nth(3, Lat1) + Nth(5, Lat1) + Nth(7, Lat1) + Nth(9, Lat1) + Nth(11, Lat1))

End Function
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You can't nest procedures within other procedures.

You could do it something like this, though I'm skeptical of the formula:

Code:
Option Explicit
Const pi          As Double = 3.14159265358979
Const D2R         As Double = pi / 180
Const f           As Double = 1 / 298.257223563
Const e           As Double = (2 * f - f ^ 2) ^ 0.5
Const a           As Double = 21600 / (2 * pi)
 
Function MP(ByVal Lat1 As Double)
    Lat1 = D2R * Lat1
    MP = a * Log(Tan(D2R * 45 + Lat1 / 2)) - _
         a * (Nth(1, Lat1) + Nth(3, Lat1) + Nth(5, Lat1) + Nth(7, Lat1) + Nth(9, Lat1) + Nth(11, Lat1))
End Function
 
Function Nth(n, Lat1)
    Nth = e ^ (n + 1) / n * Sin(Lat1) ^ n
End Function

Log in VBA is natural log.

EDIT: I'm skeptical of both formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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