Sub Test()
Dim dArrData(1 To 100, 1 To 10) As Double
Dim dAutoCoVar() As Double
Dim j As Long, k As Long
' fill the array with some bogus data
Randomize
For j = 1 To 100
For k = 1 To 10
dArrData(j, k) = Rnd
Next k
Next j
' write to the worksheet, for debug
Range("A1:J100").Value = dArrData
' calculate the autocovariance matrix
dAutoCoVar = Autocovar(dArrData)
' write to the worksheet, for debug
Range("L1:U10").Value = dAutoCoVar
End Sub
Function Autocovar(dArrData() As Double) As Double()
Dim dArrResult() As Double
Dim j As Long, k As Long
' redim the result array as a square array.
ReDim dArrResult(1 To UBound(dArrData, 2), 1 To UBound(dArrData, 2))
' calculate the autocovariance matrix
For j = 1 To UBound(dArrData, 2)
For k = 1 To UBound(dArrData, 2)
With Application.WorksheetFunction
dArrResult(j, k) = .Covar(.Index(dArrData, 0, j), .Index(dArrData, 0, k))
End With
Next k
Next j
Autocovar = dArrResult
End Function