Hi,
I'm new to using VBA, but looking to learn. I'm having trouble with the code for a correlation matrix function. The code is below and I keep getting a #NAME? error but I can't figure out where the issue is.
Function CorrelationMatrix(rng As Range) As Variant
Dim i As Integer
Dim j As Integer
Dim NumColumns As Integer
NumColumns = rng.Columns.Count - 1
Dim matrix() As Double
ReDim matrix(NumColumns, NumColumns)
For i = 0 To NumColumns
For j = i To NumColumns
matrix(i, j) = WorksheetFunction.Correl(rng.Columns(i + 1), rng.Columns(j + 1))
Next j
Next i
CorrelationMatrix = matrix
End Function
Any help/advice would be greatly appreciated!
I'm new to using VBA, but looking to learn. I'm having trouble with the code for a correlation matrix function. The code is below and I keep getting a #NAME? error but I can't figure out where the issue is.
Function CorrelationMatrix(rng As Range) As Variant
Dim i As Integer
Dim j As Integer
Dim NumColumns As Integer
NumColumns = rng.Columns.Count - 1
Dim matrix() As Double
ReDim matrix(NumColumns, NumColumns)
For i = 0 To NumColumns
For j = i To NumColumns
matrix(i, j) = WorksheetFunction.Correl(rng.Columns(i + 1), rng.Columns(j + 1))
Next j
Next i
CorrelationMatrix = matrix
End Function
Any help/advice would be greatly appreciated!