Hi,
I'm assumed that you only have excel files in these folder and that the data is in the structure you provided in a sheet called "Daily Sales by Order". The following macro will open each file in each folder consecutively, extract the data, put it in the new master sheet, close the file and move on to the next file.
To be honest, all the opening and closing of files could take some time and so I would advise you to do this in batches until you know how long the whole process will take. There are also other ways of extracting data from closed workbooks but it would take me some time to be proficient enough to help you out.
Hope this helps.
abousetta
Option Explicit
Dim Dic As Object
Sub FilesInFolder()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set Dic = CreateObject("Scripting.Dictionary")
' Loop through all subfolders
ListFilesInFolder "C:\Users\MyComputer'sName\Desktop\Test", True ' << Change to your needs
Set Dic = Nothing
Range("A1").Value = "Folder name|File name|Name|Address|Town|Postcode|Phone number|Transaction type|Marketing"
Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, OtherChar:="|"
Application.DisplayAlerts = True
End Sub
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
Dim s As String
Dim arr
Dim fso As Object
Dim SourceFolder, FileItem, SubFolder
Dim R As Long, LR As Long
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder(SourceFolderName)
For Each FileItem In SourceFolder.Files
Dic.RemoveAll
Workbooks.Open FileItem.Path, False
LR = Sheets("Daily Sales by Order").Range("A" & Rows.Count).End(xlUp).Row
For R = 3 To LR
s = SourceFolder.Name & "|" & ActiveWorkbook.Name & "|" & _
Application.IfError(Cells(R, "C").Value, "") & "|" & _
Application.IfError(Cells(R, "D").Value, "") & "|" & _
Application.IfError(Cells(R, "E").Value, "") & "|" & _
Application.IfError(Cells(R, "F").Value, "") & "|" & _
Application.IfError(Cells(R, "G").Value, "") & "|" & _
Application.IfError(Cells(R, "H").Value, "") & "|" & _
Application.IfError(Cells(R, "I").Value, "")
Dic.Item(s) = 0
Next
ActiveWorkbook.Close False
' Print results to sheet
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & LR + 1 & ":A" & UBound(Dic.Keys) + 2) = Application.Transpose(Dic.Keys)
Next
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set fso = Nothing
End Sub
Bookmarks