Hi
I'm trying to write some code to return a matrix as a range from a function. (The reason is that I already have functions that take in ranges as input, and i want to use this function there)
Code
Function Correlcalc(Stock1 As Range, Stock2 As Range, Stock3 As Range) As Range
Dim RangeArray(3) As Range
Dim Correls(3, 3) As Double
Dim correlrange As Range
Set RangeArray(1) = Stock1
Set RangeArray(2) = Stock2
Set RangeArray(3) = Stock3
For i = 1 To 3
For j = 1 To 3
Correls(i - 1, j - 1) = Application.WorksheetFunction.Correl(RangeArray(i), RangeArray(j))
Next j
Next i
'/where it's not working
correlrange.Resize(3, 3) = Correls
Set Correlcalc = correlrange
End Function
Display More
I think the problem lies in the line
and i don't know how to transfer the array to a range. The tips i tried to modify from the forum don't seem to work