Option Explicit
Sub test()
Dim arr, pth, f, m, pos, t, i, j, max
pth = ThisWorkbook.Path & "\"
f = Dir(pth & "*.txt")
pos = Array(2, 3, 5, 6)
ReDim brr(99, 1 To 6)
Do While f <> ""
m = Val(Left(Right(f, 6), 2))
If max < m Then max = m
Open pth & f For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
For i = 0 To UBound(arr, 1)
t = Split(arr(i), ",")
For j = 0 To UBound(t)
brr(m, pos(j)) = brr(m, pos(j)) + Val(t(j))
Next
Next
f = Dir
Loop
For i = 1 To max
For j = 0 To UBound(pos)
brr(0, pos(j)) = brr(0, pos(j)) + brr(i, pos(j))
Next
brr(i, 1) = brr(i, 2) + brr(i, 3)
brr(0, 1) = brr(0, 1) + brr(i, 1)
brr(i, 4) = brr(i, 5) + brr(i, 6)
brr(0, 4) = brr(0, 4) + brr(i, 4)
Next
[b2].Resize(max + 1, UBound(brr, 2)) = brr
End Sub |