Combining excel files

John44

New Member
Joined
Oct 1, 2014
Messages
45
Hi,

I get sent about 100 excel files of products sold and most have only a few lines of excel. What I would like to do is have one excel files with a hundred tabs. Is there a way I can quickly do this as cutting and pasting all these files into tabs is so time consuming.

Thanks

John
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
1620908833104.png


Like this with the date field bit changing.
 
Upvote 0
This should work.

Please open a new XLSM file, and create a worksheet named "List with source files".
Add this macro to the XLSM file.
Save this XLSM file in a DIFFERENT folder then the folder with your source files.
In the macro, change the path behind "Folderlocation", to match the path with your source files.

VBA Code:
Sub Identify_source_files()

 
    Sheets("List with source files").Select
    Columns("A:A").ClearContents
    Range("A1").Select

Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Integer

' This is the location of the source files!
' Do not put the macro file in the same folder!
FolderLocation = "C:\Users\peter\OneDrive\Documents\MR Excel\OpenPO"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(FolderLocation)

For Each oFile In oFolder.Files

' Identify the source file
    Cells(i + 1, 1) = oFile.Name
    i = i + 1
' Open the source file
    Dim wkb As Workbook
    Set wkb = Workbooks.Open(FolderLocation & "\" & Range("A" & i).Value)
' Copy the contents of the source file
    ActiveSheet.UsedRange.Copy
' Return to the master file
    Workbooks("OpenPO.xlsm").Activate
' Add new worksheet
    Sheets.Add After:=ActiveSheet
' Paste data
    Range("A1").Select
    ActiveSheet.Paste
' Close source file
    Sheets("List with source files").Select
    Workbooks(Range("A" & i).Value).Close SaveChanges:=False


Next oFile


End Sub
 
Last edited:
Upvote 0
which one is XLSM? Is it the normal excel or macro-enabled? Then how do I add the code to it?
 
Upvote 0
The macro enabled file is XLSM.

To add the code, go to visual basic (Alt-F11).
Insert a new module
In the new module, paste the VBA code I provided earlier.
 
Upvote 0
Ok done that. There were loads of other macros for add ins etc and boxes opening. Now what do I do?
 
Upvote 0
In the macro, please change:

Workbooks("OpenPO.xlsm").activate
to
Workbooks("Combine Files MK.xlsm").activate

Should have mentioned that in my first post.
After that you can run the macro.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

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