View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
LesHurley LesHurley is offline
external usenet poster
 
Posts: 61
Default Re-entrant function

Dana; you seem to be missing one key fact that I have always specified. I
have never had any trouble with the simple formula {=xx(j,k)} regardless of
the orientation of j & K nor of the orientation of the selection for the
answer. The problem arises when the formula is re-entrant as in
{=xx(xx(i,j),xx(k,l))}. The first pass calculates xx(i,j), no problem. The
second pass calculates xx(k,l), still no problem. On the third pass it
calculates the CP of the results of the first two passes. Still no problem
if the selection for the answer is horizontal, but it crashes if the
selection is vertical. In the first two passes, Va and Vb are both Range
objects while on the third pass they are both variant objects. If you execute
my original post you will see that the Debug.Print TypeName(Va), TypeName(Vb)
statement right after the Function declaration confirms that. It's all very
mysterious to me. I tried declaring the, Function xx(Va, Vb) As Range but
that produces a Type Mismatch at the final assignment, xx=CP. I tried some
other things too to no avail.
--
Thanks for your help


"Dana DeLouis" wrote:

Here's a modification to allow you to enter your own numbers if you wish.
I selected both a 3-Cell Verticle, or 3-Cell Horizontal area and
Array-Entered the following:

=Cross(A1:A3,{4,-7,2})

Function Cross(xx, yy)
'// = = = = = = =
'// Cross Product
'// = = = = = = =

Dim x As Variant
Dim y As Variant
Dim CP(1 To 3)

'// Put input into 1-Dim form
If TypeName(xx) = "Range" Then
x = xx.Value
If xx.Rows.Count 1 Then
x = Tr1(x)
Else
x = Tr2(x)
End If
Else
x = xx
End If

If TypeName(yy) = "Range" Then
y = yy.Value
If yy.Rows.Count 1 Then
y = Tr1(y)
Else
y = Tr2(y)
End If
Else
y = yy
End If

CP(1) = x(2) * y(3) - x(3) * y(2)
CP(2) = x(3) * y(1) - x(1) * y(3)
CP(3) = x(1) * y(2) - x(2) * y(1)

If Application.Caller.Columns.Count 1 Then
Cross = CP 'Horizontal
Else
Cross = Tr1(CP) 'Verticle
End If
End Function

--
HTH :)
Dana DeLouis

<Snip