View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
J.E. McGimpsey J.E. McGimpsey is offline
external usenet poster
 
Posts: 493
Default sqr function in vba

MMULT returns an array. When a function returns an array to a cell,
the first element is put in the cell.

Sqr() however, takes a value, not an array, as an argument. If you
want to take the square root of the array's first element, use

MyFormula = Sqr( _
.MMult(.Transpose(Array1), .MMult(Array2, Array1))(1, 1))

In article ,
(Gabriel) wrote:

Hi,

When I add sqr function to the below myFormula it doesn't work anymore.

So, this works fine:
Function MyFormula(Array1, Array2) As Variant
With Application.WorksheetFunction
MyFormula = .MMult(.Transpose(Array1), .MMult(Array2, Array1))
End With
End Function

This doesn't work
MyFormula = Sqr(.MMult(.Transpose(Array1), .MMult(Array2, Array1)))

Does anyone know what am I missing here?

Much obliged
Gabriel