For the data uploaded.
Sub test()
Dim a, b, e, i As Long, ii As Long, n As Long, t As Long, w, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
a = Sheets("statement").[a4].CurrentRegion.Value
For i = 2 To UBound(a, 1)
If Not dic.exists(a(i, 3)) Then
ReDim w(1 To UBound(a, 2) * 2 + 1)
Else
w = dic(a(i, 3))
End If
For ii = 1 To UBound(a, 2)
w(ii + IIf(a(i, 2) >= 0, UBound(a, 2) + 1, 0)) = a(i, ii)
Next
dic(a(i, 3)) = w
Next
ReDim a(1 To dic.Count), b(1 To dic.Count)
For Each e In dic
If dic(e)(2) + dic(e)(6) = 0 Then
n = n + 1: a(n) = dic(e)
Else
t = t + 1: b(t) = dic(e)
End If
Next
If n Then
ReDim Preserve a(1 To n)
With Sheets("reconciled").Columns("a:g")
Intersect(.Cells, .Rows("5:" & .Cells.SpecialCells(11).Row)).ClearContents
.Rows(5).Resize(n) = Application.Index(a, 0, 0)
End With
End If
If t Then
ReDim Preserve b(1 To t)
With Sheets("unreconciled").Columns("a:g")
Intersect(.Cells, .Rows("5:" & .Cells.SpecialCells(11).Row)).ClearContents
With .Rows(5).Resize(t)
.Value = Application.Index(b, 0, 0)
.SpecialCells(4).Delete xlShiftUp
End With
End With
End If
End Sub
Bookmarks