Hi,
UDF functions can be called from a Worksheet, given they are 'Public functions' and are defined inside a Module (not in the Worksheet Code).
But if a UDF function has variables that are defined as user defined type variables it will simply give a #VALUE! error:
For example, if in a cell we have the formula (with the code inside a macro):
= fATanPoints(fXY2Point(1;2);fXY2Point(3;4))
It will return #VALUE!
Instead, calling another UDF function like:
=fATanPointsXY(1;2;3;4)
Will give as answer = 0.553, that is correct.
The question is, how can I call the UDF function fATanPoints that has User Defined Type variables in order to get the same result?
I suppose that in Excel 97 the CALL() function will solve this, but now, I'm stuck.
Thanks in advance.
UDF functions can be called from a Worksheet, given they are 'Public functions' and are defined inside a Module (not in the Worksheet Code).
But if a UDF function has variables that are defined as user defined type variables it will simply give a #VALUE! error:
For example, if in a cell we have the formula (with the code inside a macro):
= fATanPoints(fXY2Point(1;2);fXY2Point(3;4))
It will return #VALUE!
Instead, calling another UDF function like:
=fATanPointsXY(1;2;3;4)
Will give as answer = 0.553, that is correct.
Code:
Public Type POINT
X As Double
Y As Double
End Type
Public Function fXY2Point(ByRef X As Double, ByRef Y As Double) As POINT
Dim TestPoint As POINT
With TestPoint
.X = X
.Y = Y
End With
fXY2Point = TestPoint
End Function
Public Function fATanPoints(ByRef Point1 As POINT, ByRef Point2 As POINT) As Double
'Return the Atan of the line between two points (for this example, didn't implemented error traps, as they're used valid values that has no errors)
fATanPoints = Atn(Point2.Y - Point1.Y) / (Point2.X - Point1.X)
End Function
Public Function fATanPointsXY(ByRef X1 As double, byref Y1 As double, byref X2 As double, byref Y2 As double) As Double
'Return the Atan of the line between two points (for this example, didn't implemented error traps, as they're used valid values that has no errors)
fATanPointsXY = Atn(Y2 - Y1) / (X2 - X1)
End Function
The question is, how can I call the UDF function fATanPoints that has User Defined Type variables in order to get the same result?
I suppose that in Excel 97 the CALL() function will solve this, but now, I'm stuck.
Thanks in advance.