Number_of_csvs = Control_Sheet.Range("A10").End(xlDown).Row
is an error because A10:A... are empty
Rather Number_of_csvs = j (number of CSV files = j)
-----------
Try it
Sub SUM_WBs()
Dim csv As Variant, i As Long, j As Long, k As Long, wb As Workbook
Dim result(), data()
Application.Calculation = xlManual
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ReDim result(1 To 5, 1 To 5) ' change to (1 to 200, 1 to 200) for 200x200 matrix
Set Control_Sheet = ThisWorkbook.Worksheets("Control")
ImportFilePath = Control_Sheet.Cells(5, 2) ' folder with csv's becomes ImportFilePath variable
csv = Dir(ImportFilePath & "*.csv")
' k = 0
Do While csv <> ""
If InStr(csv, "pax") > 0 Then 'if the csv contains 'pax' in the filename
' k = k + 1
Set wb = Workbooks.Open(ImportFilePath & csv) 'wb opens the csv
data = wb.Worksheets(1).Range("B2").Resize(5, 5).Value ' change to (200, 200) for 200x200 matrix
wb.Close SaveChanges:=False
For i = 1 To UBound(result, 1)
For j = 1 To UBound(result, 2)
result(i, j) = result(i, j) + data(i, j) ' SUM
Next j
Next i
' Control_Sheet.Cells(10 + k, 2).Value = csv ' write the csv filename
End If
csv = Dir()
Loop
ThisWorkbook.Worksheets("All").Range("B2").Resize(UBound(result, 1), UBound(result, 2)).Value = result ' change to (200, 200) for 200x200 matrix
Application.ScreenUpdating = True
End Sub
In your free time, learn PQ
Bookmarks