Sub MoveData3()
Dim rw As Long, lr As Long, i As Long, j As Long, wsS As Worksheet, wsD As Worksheet, ar() As Variant
Application.ScreenUpdating = False
Set wsS = Sheets("From Here")
Set wsD = Sheets("To Here")
rw = wsD.Cells(Rows.Count, 1).End(xlUp).Row
lr = wsS.Cells(Rows.Count, 1).End(xlUp).Row
wsD.Range("A2:J" & rw + 1).ClearContents
rw = 1
ReDim Preserve ar(10, rw)
For i = 2 To lr
With wsD
ReDim Preserve ar(10, rw)
ar(1, rw) = wsS.Cells(i, 1) 'Ref
ar(2, rw) = "ABC1"
ar(3, rw) = "GBP"
ar(4, rw) = CLng(wsS.Cells(i, 9)) 'Date
ar(5, rw) = "Loan"
ar(6, rw) = wsS.Cells(i, 6) 'Value
ar(7, rw) = "Loan"
ar(8, rw) = "123"
ar(9, rw) = wsS.Cells(i, 4) 'Practice Ref
ar(10, rw) = "P" & Right(wsS.Cells(i, 1), 5)
rw = rw + 1
For j = 1 To wsS.Cells(i, 7)
ReDim Preserve ar(10, rw)
ar(1, rw) = wsS.Cells(i, 1)
ar(2, rw) = ar(2, rw - 1)
ar(3, rw) = ar(3, rw - 1)
If j = 1 Then ar(4, rw) = CLng(wsS.Cells(i, 9)) 'Date
If j <> 1 Then ar(4, rw) = CLng(Application.WorksheetFunction.EoMonth(DateAdd("m", 1, ar(4, rw - 1)), 0)) 'Date
ar(5, rw) = wsS.Cells(i, 4) & "-Instalment " & j
ar(6, rw) = wsS.Cells(i, 6) / wsS.Cells(i, 7) * -1
ar(7, rw) = "Instal " & j
ar(8, rw) = ar(8, rw - 1)
ar(9, rw) = wsS.Cells(i, 4)
ar(10, rw) = "P" & Right(wsS.Cells(i, 1), 5)
rw = rw + 1
Next
End With
Next
Sheet2.Range("A2:J" & rw) = Tx2DArr(ar)
End Sub
Function Tx2DArr(inputArray As Variant) As Variant
Dim x As Long, yUbound As Long, y As Long, xUbound As Long, tempArray As Variant
xUbound = UBound(inputArray, 2)
yUbound = UBound(inputArray, 1)
ReDim tempArray(1 To xUbound, 1 To yUbound)
For x = 1 To xUbound
For y = 1 To yUbound
tempArray(x, y) = inputArray(y, x)
Next y
Next x
Tx2DArr = tempArray
End Function
I tried it with 20 loans of 48 months (980 rows of output) and the results before and after were very similar.