Merging multiple workbooks into one

wheellp

New Member
Joined
Aug 2, 2016
Messages
30
I found a code on www.oaultimate.com to merge multiple workbooks into one and it works perfect. However I ran into a problem. On the multiple documents they have 2 sets of columns that provide the same type of information. is there a way to make the macro merge all of the documents' and put the info in the 2nd set of columns directly under the first? the info under the 2nd column is different but is in the same format.

here is an example of the columns:

[TABLE="width: 912"]
<tbody>[TR]
[TD]animal
[/TD]
[TD][/TD]
[TD]name
[/TD]
[TD][/TD]
[TD]owner
[/TD]
[TD][/TD]
[TD]shots
[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]date
[/TD]
[TD][/TD]
[TD]animal
[/TD]
[TD][/TD]
[TD]name
[/TD]
[TD][/TD]
[TD]owner
[/TD]
[TD][/TD]
[TD]shots
[/TD]
[TD][/TD]
[TD]date
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Code being used:
Code:
[COLOR=#0000FF][B]Sub[/B][/COLOR] simpleXlsMerger[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#0000FF][B]Dim[/B][/COLOR] bookList [COLOR=#0000FF][B]As[/B][/COLOR] Workbook
[COLOR=#0000FF][B]Dim[/B][/COLOR] mergeObj [COLOR=#0000FF][B]As[/B][/COLOR] [COLOR=#6A5ACD]Object[/COLOR], dirObj [COLOR=#0000FF][B]As[/B][/COLOR] [COLOR=#6A5ACD]Object[/COLOR], filesObj [COLOR=#0000FF][B]As[/B][/COLOR] [COLOR=#6A5ACD]Object[/COLOR], everyObj [COLOR=#0000FF][B]As[/B][/COLOR] [COLOR=#6A5ACD]Object[/COLOR]
Application[COLOR=#000000].[/COLOR][COLOR=#000000]ScreenUpdating[/COLOR] [COLOR=#000000]=[/COLOR] [COLOR=#0000FF][B]False[/B][/COLOR]
[COLOR=#0000FF][B]Set[/B][/COLOR] mergeObj [COLOR=#000000]=[/COLOR] [COLOR=#000066]CreateObject[/COLOR][COLOR=#000000]([/COLOR][COLOR=#A52A2A]"Scripting.FileSystemObject"[/COLOR][COLOR=#000000])[/COLOR]
 
[COLOR=#008000][I]'change folder path of excel files here[/I][/COLOR]
[COLOR=#0000FF][B]Set[/B][/COLOR] dirObj [COLOR=#000000]=[/COLOR] mergeObj[COLOR=#000000].[/COLOR][COLOR=#000000]Getfolder[/COLOR][COLOR=#000000]([/COLOR][COLOR=#A52A2A]"D:\change\to\excel\files\path\here"[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#0000FF][B]Set[/B][/COLOR] filesObj [COLOR=#000000]=[/COLOR] dirObj[COLOR=#000000].[/COLOR][COLOR=#000000]Files[/COLOR]
[COLOR=#0000FF][B]For[/B][/COLOR] [COLOR=#0000FF][B]Each[/B][/COLOR] everyObj [COLOR=#0000FF][B]In[/B][/COLOR] filesObj
[COLOR=#0000FF][B]Set[/B][/COLOR] bookList [COLOR=#000000]=[/COLOR] Workbooks[COLOR=#000000].[/COLOR][COLOR=#000000]Open[/COLOR][COLOR=#000000]([/COLOR]everyObj[COLOR=#000000])[/COLOR]
 
[COLOR=#008000][I]'change "A2" with cell reference of start point for every files here[/I][/COLOR]
[COLOR=#008000][I]'for example "B3:IV" to merge all files start from columns B and rows 3 [/I][/COLOR]
[COLOR=#008000][I]'If you're files using more than IV column, change it to the latest column[/I][/COLOR]
[COLOR=#008000][I]'Also change "A" column on "A65536" to the same column as start point[/I][/COLOR]
Range[COLOR=#000000]([/COLOR][COLOR=#A52A2A]"D4:IV"[/COLOR] [COLOR=#000000]&[/COLOR] Range[COLOR=#000000]([/COLOR][COLOR=#A52A2A]"A65536"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#0000FF][B]End[/B][/COLOR][COLOR=#000000]([/COLOR]xlUp[COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Row[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Copy[/COLOR]
ThisWorkbook[COLOR=#000000].[/COLOR][COLOR=#000000]Worksheets[/COLOR][COLOR=#000000]([/COLOR][COLOR=#A52A2A]1[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Activate[/COLOR]
 
[COLOR=#008000][I]'Do not change the following column. It's not the same column as above[/I][/COLOR]
Range[COLOR=#000000]([/COLOR][COLOR=#A52A2A]"A65536"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#0000FF][B]End[/B][/COLOR][COLOR=#000000]([/COLOR]xlUp[COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Offset[/COLOR][COLOR=#000000]([/COLOR][COLOR=#A52A2A]1[/COLOR], [COLOR=#A52A2A]0[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]PasteSpecial[/COLOR]
Application[COLOR=#000000].[/COLOR][COLOR=#000000]CutCopyMode[/COLOR] [COLOR=#000000]=[/COLOR] [COLOR=#0000FF][B]False[/B][/COLOR]
bookList[COLOR=#000000].[/COLOR][COLOR=#000000]Close[/COLOR]
[COLOR=#0000FF][B]Next[/B][/COLOR]
[COLOR=#0000FF][B]End[/B][/COLOR] [COLOR=#0000FF][B]Sub
[/B][/COLOR]
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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