Need help with basic covariance function

Joined
May 18, 2011
Messages
1
Reaction score
0
Function VarCovar(rng As Range) As Variant
Dim i As Integer
Dim j As Integer
Dim numCols As Integer
numCols = rng.Columns.Count
Dim matrix() As Double
ReDim matrix(numCols - 1, numCols - 1)
For i = 1 To numCols
For j = 1 To numCols
matrix(i - 1, j - 1) = Application.WorksheetFunction.Covr(rng.Columns(i), rng.Columns(j))
Next j
Next i
VarCovar = matrix

End Function
Code:
above is the code that I put into a function.  I have a 4x4 range of returns, and I am trying to compute a 4x4 variance-covariance range with given Function above.

I return a 4x4 range of #value! in all cells. I can not, for the life of me, figure out my error.

I would greatly appreciate any help.

Chris
 
Back
Top