kisslaszlo123
New Member
- Joined
- Apr 16, 2020
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
Hello,
I have an excel sheet with multiple columns and I need to create correlation matrix for some columns that are not necessarily next to each other. I tried to replace the range with paramarray in an UDF, but didn't work and I have no idea about how to solve this problem.
Function CorrelationMatrix(ParamArray rng() As Variant) 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
Thanks for your help in advance!
L.
I have an excel sheet with multiple columns and I need to create correlation matrix for some columns that are not necessarily next to each other. I tried to replace the range with paramarray in an UDF, but didn't work and I have no idea about how to solve this problem.
Function CorrelationMatrix(ParamArray rng() As Variant) 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
Thanks for your help in advance!
L.