Help with loop VBA

MrMan32

New Member
Joined
Nov 1, 2018
Messages
12
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
 
Thanks, Fluff. And sorry about that.

I think that solved the path problem. Now when I run the code, I don't get any error messages but nothing happens.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Do any files get opened?
 
Upvote 0
I don't think so. Nothing opens on my screen.

Again, I'm new to loop but I was assuming that the spreadsheets would all be "opened" behind the scenes without me actually seeing them on my computer.
 
Upvote 0
Try stepping through the code again using F8, what happens?
 
Upvote 0
In that case what does this say in the immediate window
Code:
Sub chk()
Debug.Print Sheets("Master Summary").Range("A" & Rows.Count).End(xlUp).Offset(1).Row
End Sub
 
Upvote 0
In that case the only thing I can think of, if the other workbooks are opening, is that there is no data in A1:E20, to copy over
 
Upvote 0
There is definitely data in those cells. Any other thoughts? Any other ideas on how to copy and paste data from numerous spreadsheets (the same range, the same sheet name) into a single master sheet?
 
Upvote 0
If it's opening all the other workbooks, then I've no idea why it's not working.
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,313
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top