Processing data from multiple files

skipwith

New Member
Joined
Sep 19, 2006
Messages
6
Hi all,

I wonder if anyone has come across this scenario previously :-

I have a series of all spreadsheets all containing the same number of sheets with the data all in the same format. They are all stored in the same folder.

From one other spreadsheet is it possible to open each spreadsheet in the folder (The file names all change but will remain .xls format) and retrieve data accordingly, returning it all to a central spreadsheet?.

Thanks.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

svg109

Board Regular
Joined
Mar 1, 2005
Messages
64
Hello skipwith

you could try something like this:

Code:
Sub getdata()

Dim filename, fileselected
Dim a1(1 To 10)    'this is an array to hold your data, change dimensions as necessary
Dim WB As Workbook

ChDrive ("C:")          'Set Current directory C:\
ChDir ("C:\your default folder")

fileselected = Application.GetOpenFilename("Excel Files, *.xls", , "Select your Files", , True)
If StrComp(TypeName(fileselected), "Boolean", vbTextCompare) = 0 Then
        ChDrive ("C:")
        Exit Sub
End If

j = 1

For Each filename In fileselected
Application.DisplayAlerts = False

        Set WB = Workbooks.Open(filename, True, True)
        Sheets("Front").Select
                
        For i = 1 To 10           
              a1(i) = Sheets(1).Cells(0 + i, 1).Value      'Change location of your data as necessary
        Next i
        
        WB.Close False
        
        ActiveWorkbook.Activate
        Sheets(1).Select
        
        For i = 1 To 10
            Cells(i, j).Value = a1(i)
        Next i
        
        Erase a1
        
        j = j + 1
        
Next

Set WB = Nothing
application.displayalerts = true

End Sub

You will need to change some things around to match your data..

See if this works..
-SG
 

Forum statistics

Threads
1,136,991
Messages
5,679,014
Members
419,799
Latest member
APInfa

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
Top