Public Sub CallData()
Dim strFile As String
Dim strPath As String
Dim Found As Range
Dim i As Long
Dim j As Long
Dim ws As Worksheet
Dim NextRow As Long
Set ws = ActiveSheet 'Destination worksheet
NextRow = ws.Range("A" & Rows.Count).End(xlUp).Row
strPath = "P:\My Documents\Transport Figures\Year\"
Application.ScreenUpdating = False
For i = 27 To 78
j = IIf(i < 53, i, i - 52) '27 to 52 then 1 to 26
strFile = Dir(strPath & j & " week*")
If strFile <> "" Then
Workbooks.Open strPath & strFile
Set Found = Range("B:B").Find(What:="GAS DRIVERS TOTAL", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Found Is Nothing Then
NextRow = NextRow + 1
Rows(Found.Row).Range("F1,R1,U1:W1,AE1").Copy _
Destination:=ws.Cells(NextRow, "A")
Else
'Row not found
End If
ActiveWorkbook.Close SaveChanges:=False
Else
'Week not found
End If
Next i
Application.ScreenUpdating = True
MsgBox "Weeks copied.", vbInformation, "Copy Complete"
End Sub
The above code was used to extract the data from the columns in the array, on the row where the text "Gas Driver" appeared on the worksheet "WEEK" of every workbook in the folder "P:\My Documents\Transport Figures\Year". Data was displayed on sheet 1 of a workbook with the code in a module. All files were similarly called but you may need to just refer to every workbook in folder
You should be able to adapt for your use by adjusting requirements, hop it gives some guidance
Bookmarks