Public Function v2(LeftMatrix As Range, RightMatrix As Range) As Variant()
Dim e As Integer, s As Integer
e = LeftMatrix.Rows.Count
s = LeftMatrix.Columns.Count
ReDim m(1 To e, 1 To s + 1)
Dim i As Integer, j As Integer, k As Integer
For i = 1 To e
For j = 1 To s + 1
If j <= s Then
m(i, j) = LeftMatrix(i, j)
Else
m(i, j) = RightMatrix(i, 1)
Next j
Next i
For i = 1 To e
For j = 1 To s + 1
Cells(i, j) = m(i, j)
Next j
Next i
End Function
I'm selecting two matrices from my worksheet and trying to merge them into a single matrix but I keep getting the ref error.