Hello,
I am trying to write a code to input a formula in VBA which returns a matrix, I am not too sure if the error is in the concatenation of the address or the creation of a matrix array.
Help is much appreciated!
Function linReg(y As Range, x As Range) As Variant
Dim Anchor As Range
Dim xRow As Integer
Dim xCol As Integer
Dim yRow As Integer
Dim xColAddress As Integer
xRow = x.Rows.Count
xCol = x.Columns.Count
yRow = y.Rows.Count
xColAddress = xCol + 1
Set Anchor = Worksheets("TakeHomeAssignmentQns2").Range("A1")
If yRow = xRow Then
Worksheets("TakeHomeAssignmentQns2").Range("B10:D15").FormulaArray = "=MMULT(MINVERSE(MMULT(TRANSPOSE(" & _
Anchor.Cells(1, 2).Address & ":" & Anchor.Cells(xRow, xColAddress).Address & ");" & _
Anchor.Cells(1, 2).Address & ":" & Anchor.Cells(xRow, xColAddress).Address & "));MMULT(TRANSPOSE(" & _
Anchor.Cells(1, 2).Address & ":" & Anchor.Cells(xRow, xColAddress).Address & ");" & _
Anchor.Cells(1, 9).Address & ":" & Anchor.Cells(yRow, 9).Address & "))"
Else
MsgBox "For function to work, number of rows in matrices x and y must be equal"
End If
End Function
Bookmarks