View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 66
Default Application.WorksheetFunction.MMult

"Gabriel" wrote...
....
In a worksheet the calcul would look like this
{=MMULT(myVector,TRANSPOSE(myVector))}. If myVector is for instance
7;8;9 then the result would simply be 49. However, when I call the
Test vba Function it just doesn't work:

Function Test(myVector) As Double

Test = Application.WorksheetFunction.MMult(MyVector, _
Application.WorksheetFunction.Transpose(MyVector))

End Function

Am I missing somethin here?


Yes - an explanation of what you mean by 'it just doesn't work'. Does it
generate syntax errors, runtime errors, or return the wrong result?

In any case, it's a mystery why you're not using

Test = Application.WorksheetFunction.SumProduct(myVector, myVector)

Note: if your vector is a vertical vector, then

MMULT({a;b;c},TRANSPOSE({a;b;c})) = {a*a,a*b,a*c;b*a,b*b,b*c;c*a,c*b,c*c}

Meaning that if you want a scalar result (the dot product of a vector with
itself), then for horizontal vectors your function is OK, but for vertical
vectors you must use

Test = Application.WorksheetFunction.MMult( _
Application.WorksheetFunction.Transpose(MyVector), _
MyVector)

If vectors could be both vertical and horizontal, SUMPRODUCT makes much more
sense than MMULT.