This code prints the values of an array into a range, but for some odd reason only the first item of the array (array(1)
if you will) is being pasted into every cell in the aforementioned range. This is the code itself:
With ws2
Dim arr5() As Variant
Set clls = .Range(.Cells(2, 8), .Cells(lr(ws2, 1), 9))
arr5 = clls.Value2
End With
lb1 = LBound(arr5, 1)
lb2 = LBound(arr5, 2)
ub1 = UBound(arr5, 1)
lb2 = UBound(arr5, 2)
Dim arr6() As Variant
ReDim arr6(lb1 To ub1)
With ws2
For rows = 1 To lr(ws2, 1) - 1
debe = arr5(rows, 1)
habr = arr5(rows, 2)
arr6(rows) = debe - habr
Next rows
Set clls = .Range(.Cells(2, 10), .Cells(lr(ws2, 1), 10))
clls.Value = arr6
End With
The lr(ws, col) udf takes ws as worksheet and col (column) as long and finds the index of the last row in said column within that worksheet using the End.XlUp.Row method. Find it's code below in case you wish to inspect it:
Public Function lr(ws As Worksheet, col As Long) As Long
lr = ws.Cells(ws.rows.Count, col).End(xlUp).row
End Function
Lastly, this is the sort of data that the code is working with: