Sub test()
Dim a, b, i As Long, n As Long, t As Long
a = Sheets("asd").[a1].CurrentRegion.Value
ReDim b(1 To UBound(a, 1) * 3, 1 To 3)
For i = 2 To UBound(a, 1)
n = n + 1: t = 1: b(n, 1) = t
b(n, 2) = a(i, 2): b(n, 3) = a(i, 3)
n = n + 1: t = t + 1: b(n, 1) = t
b(n, 2) = Split(Trim$(a(i, 2)))(1)
With Sheets(b(n, 2)).[a1].CurrentRegion
b(n, 3) = Application.Sum(.Columns(.Columns.Count)) / _
(2 + IsError(Application.Match("total", .Columns(1), 0)))
End With
n = n + 1: b(n, 1) = b(n - 1, 2) & " TOTAL": b(n, 3) = "=sum(r[-2]c:r[-1]c)"
Next
n = n + 1: b(n, 1) = "NET": b(n, 3) = "=r[-1]c-r[-4]c"
With Sheets("report").[a1].Resize(, 3)
.CurrentRegion.ClearContents
.Value = Array("ITEMS", "NAME ACCOUNT", "TOTAL")
.Rows(2).Resize(UBound(b, 1)) = b
End With
End Sub
Bookmarks