Hi Expert,
Is there a way to extract data from hundreds of files in single folder from particular range? I googled and found various options but none of them seems to be working with me.
Basically all files in one folder and range is B53:O153.
I would prefer the power query but query is bringing up only top rows and I can not figure out where to put in range, I am using Excel 2021, can anyone help to guide me please..
Also tried below code but it goes on and on and then I have to forcibly close Excel to stop.
Sub CopyValuesFromFiles()
Dim sourceFolder As String
Dim sourceFiles As Object
Dim sourceFile As Object
Dim wbSource As Workbook
Dim wsDestination As Worksheet
Dim destinationRow As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Set the path to the source folder modify accordingly
sourceFolder = "Z:\DOCUMENTS\INVOICES- 24-25"
' Set the destination worksheet modify sheet name accordingly
Set wsDestination = ThisWorkbook.Worksheets("Customers")
' Initialize the destination row
destinationRow = 2
' Create a FileSystemObject to work with files in the folder
Set sourceFiles = CreateObject("Scripting.FileSystemObject").GetFolder(sourceFolder).Files
' Loop through each file in the folder
For Each sourceFile In sourceFiles
' Check if the file is an Excel file
If sourceFile.Name Like "*.xlsm*" Then
' Open the source workbook
Set wbSource = Workbooks.Open(sourceFile.Path)
' Copy the values from B53 to O153
wbSource.Worksheets(1).Range("B53:O153").Copy
' Paste the values to the destination worksheet
wsDestination.Range("A" & destinationRow).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
' Update the destination row for the next set of values
destinationRow = destinationRow + 1
' Close the source workbook without saving changes
wbSource.Close SaveChanges:=False
End If
Next sourceFile
' Clear the clipboard
Application.CutCopyMode = False
' Display a message when the copying is complete
MsgBox "Copying customer information from files complete."
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Thanks in advance.
Is there a way to extract data from hundreds of files in single folder from particular range? I googled and found various options but none of them seems to be working with me.
Basically all files in one folder and range is B53:O153.
I would prefer the power query but query is bringing up only top rows and I can not figure out where to put in range, I am using Excel 2021, can anyone help to guide me please..
Also tried below code but it goes on and on and then I have to forcibly close Excel to stop.
Sub CopyValuesFromFiles()
Dim sourceFolder As String
Dim sourceFiles As Object
Dim sourceFile As Object
Dim wbSource As Workbook
Dim wsDestination As Worksheet
Dim destinationRow As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Set the path to the source folder modify accordingly
sourceFolder = "Z:\DOCUMENTS\INVOICES- 24-25"
' Set the destination worksheet modify sheet name accordingly
Set wsDestination = ThisWorkbook.Worksheets("Customers")
' Initialize the destination row
destinationRow = 2
' Create a FileSystemObject to work with files in the folder
Set sourceFiles = CreateObject("Scripting.FileSystemObject").GetFolder(sourceFolder).Files
' Loop through each file in the folder
For Each sourceFile In sourceFiles
' Check if the file is an Excel file
If sourceFile.Name Like "*.xlsm*" Then
' Open the source workbook
Set wbSource = Workbooks.Open(sourceFile.Path)
' Copy the values from B53 to O153
wbSource.Worksheets(1).Range("B53:O153").Copy
' Paste the values to the destination worksheet
wsDestination.Range("A" & destinationRow).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
' Update the destination row for the next set of values
destinationRow = destinationRow + 1
' Close the source workbook without saving changes
wbSource.Close SaveChanges:=False
End If
Next sourceFile
' Clear the clipboard
Application.CutCopyMode = False
' Display a message when the copying is complete
MsgBox "Copying customer information from files complete."
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Thanks in advance.