Option Explicit
Sub test()
Dim ar, br, cr, i&, r&, f, wkb As Workbook, p$
Application.ScreenUpdating = False
With [A1].CurrentRegion
.Offset(1).Clear
br = .Resize(10 ^ 3)
r = 1
End With
cr = [{2,4;3,13;5,15;7,17}]
p = ThisWorkbook.Path & "\"
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(p).Files
If f.Name Like "*.csv" Then
With GetObject(f)
With .Sheets(1).[A1].CurrentRegion
ar = Intersect(.Offset(), .Offset(1))
End With
ReDim Preserve ar(1 To UBound(ar), 1 To 17)
For i = 1 To UBound(ar)
If ar(i, 7) = "X" Then ar(i, 13) = ar(i, 4) Else ar(i, 13) = 0
If ar(i, 6) >= 30000 Or ar(i, 6) * ar(i, 3) >= 300000 Then ar(i, 15) = ar(i, 4) Else ar(i, 15) = 0
If ar(i, 7) = "X" And ar(i, 15) <> 0 Then ar(i, 17) = ar(i, 15) Else ar(i, 17) = 0
Next i
r = r + 1
br(r, 1) = .Name
For i = 1 To UBound(cr)
br(r, cr(i, 1)) = WorksheetFunction.Round(WorksheetFunction.Sum(Application.Index(ar, , cr(i, 2))) / 100, 0)
Next i
br(r, 4) = WorksheetFunction.Round(br(r, 3) / br(r, 2), 2)
br(r, 6) = WorksheetFunction.Round(br(r, 5) / br(r, 2), 2)
br(r, 8) = WorksheetFunction.Round(br(r, 7) / br(r, 2), 2)
.Close False
End With
End If
Next
[A1].Resize(r, UBound(br, 2)) = br
Application.ScreenUpdating = True
Beep
End Sub
|