question about loop to copy content in folder to a worksheet

ces005

Board Regular
Joined
Mar 13, 2006
Messages
189
Hi,

I have a bunch of .xls files in a folder on my desktop (let's call it myFolder).

If I want to copy the contents of worksheet called "Template" in every .xls file in that folder (except for the workbook I am running the macro from) , any suggestions on how to do this? I am creating a macro in the Master file to run. I am concatenating the contents to the "ALLData" worksheet in the active workbook.

-Eileen


Set wbk = ThisWorkbook
Set sht = wbk.Sheets("ALLData")

Generate an array of file names containing .xls files from the folder
Delete the file name from this list where the file name matches the current active workbook

CurrentIndex = 0

' last index is the number of entries in the array
do until CurreintIndex < LastIndex
Workbooks.Open file name in array[current index]

' select rows 2 through the last row of the worksheet to be copied
' copy those rows
' paste those rows after the last row of sht (target sheet)
loop
 
Eileen

As far as I'm aware VBA and the web aren't particularly compatible.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How do I only loop through files which do not contain the word "Master" in it? What change do I need to make to the "If" statement?

Code:
    With oSearch
        .NewSearch

        .LookIn = strDirName
        .SearchSubFolders = False
        .FileType = msoFileTypeExcelWorkbooks
        .Execute
        NextRow = 1
        For I = 1 To .FoundFiles.Count
           If Dir(.FoundFiles(I)) <> wbDst.Name Then
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,874
Members
449,056
Latest member
ruhulaminappu

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