Hello,
I'm new to the forum so thank you in advance for your help. I'm trying to use the loop function to extract and aggregate data across clients and can really use some help with my VBA code - I'm not sure where I am going wrong.
Here is what I have and am trying to do -
1) I have about 75 excel files in a folder called "2018 Clients"
2) The path to the folder is simply "Desktop\Client Folder\2018 Clients"
3) Each excel file has roughly 15 worksheets. The final worksheet is called "Summary"
4) I am trying to copy data (cells A1:E20) from every "Summary" worksheet in the folder to a single master worksheet to run data analysis.
Here is the code I'm using. I'm not getting any errors when I run the macro but the data is not populating. Any help is greatly appreciated!
Sub CombineWbks()
Dim Pth As String
Dim MstSht As Worksheet
Dim fname As String
Dim Rng As Range
Application.ScreenUpdating = False
Pth = "C:\Desktop\Client Folder\2018 Clients"
Set MstSht = ThisWorkbook.Sheets("Master Summary")
fname = Dir(Pth & "*xlsm*")
Do While Len(fname) > 0
Workbooks.Open (Pth & fname)
With Workbooks(fname)
.Sheets("Summary").Range("A1:E20").Copy MstSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
.Close , False
End With
fname = Dir
Loop
End Sub
I'm new to the forum so thank you in advance for your help. I'm trying to use the loop function to extract and aggregate data across clients and can really use some help with my VBA code - I'm not sure where I am going wrong.
Here is what I have and am trying to do -
1) I have about 75 excel files in a folder called "2018 Clients"
2) The path to the folder is simply "Desktop\Client Folder\2018 Clients"
3) Each excel file has roughly 15 worksheets. The final worksheet is called "Summary"
4) I am trying to copy data (cells A1:E20) from every "Summary" worksheet in the folder to a single master worksheet to run data analysis.
Here is the code I'm using. I'm not getting any errors when I run the macro but the data is not populating. Any help is greatly appreciated!
Sub CombineWbks()
Dim Pth As String
Dim MstSht As Worksheet
Dim fname As String
Dim Rng As Range
Application.ScreenUpdating = False
Pth = "C:\Desktop\Client Folder\2018 Clients"
Set MstSht = ThisWorkbook.Sheets("Master Summary")
fname = Dir(Pth & "*xlsm*")
Do While Len(fname) > 0
Workbooks.Open (Pth & fname)
With Workbooks(fname)
.Sheets("Summary").Range("A1:E20").Copy MstSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
.Close , False
End With
fname = Dir
Loop
End Sub