Combining data from multiple workbooks

Prometheus_au

New Member
Joined
Jan 26, 2005
Messages
12
I have a folder with 440 files.
I would like to stack the data from B6:F30 on every file into a single sheet.

I have the VB code to do this with the data on sheets within a workbook, but now need to have the data moved from seperate workbooks.

Can this be done?

Cheers.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
Here is a quick alteration from a similar question this morning.
Change the sFolderPath = "I:\" to suit your folder path.

Code:
Sub CollectAll()
On Error GoTo Exit_Line
Application.ScreenUpdating = False
Application.EnableEvents = False

Dim wbkTempBook As Workbook
Dim shtPasteSheet As Worksheet, shtTemp As Worksheet
Dim lngMaxRow As Long, lngCopyRows As Long, lngPasteRow As Long, lngIgnoreRows As Long

lngPasteRow = 7 'Row to start copying to
lngIgnoreRows = 5 'Number of Rows to ignore

Set shtPasteSheet = ThisWorkbook.Sheets(1)

sFolderPath = "I:\"

sTempName = Dir(sFolderPath & "*xls")
Do While sTempName <> ""
    Set wbkTempBook = Workbooks.Open(sFolderPath & "\" & sTempName, True, True)
    Set shtTemp = wbkTempBook.Sheets(1)
    lngMaxRow = 30
    lngCopyRows = lngMaxRow - lngIgnoreRows
    If lngMaxRow > lngIgnoreRows Then
        shtTemp.Range("A" & lngIgnoreRows + 1 & ":V" & lngMaxRow).Copy _
            shtPasteSheet.Range("A" & lngPasteRow & ":V" & lngPasteRow + lngCopyRows - 1)
        lngPasteRow = lngPasteRow + lngCopyRows
    End If
    wbkTempBook.Close (False)
    sTempName = Dir
Loop

Exit_Line:
Application.EnableEvents = True
Application.ScreenUpdating = True
If Err.Number <> 0 Then MsgBox Err.Description
End Sub
 

Prometheus_au

New Member
Joined
Jan 26, 2005
Messages
12
Thanks CraigM,

After some initial difficulty (with the user not the code) It's working fine and saving heaps of time.

Cheers
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,483
Messages
5,770,361
Members
425,612
Latest member
martinijr

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