Copy the code in a Standard module of your workbook, if you just started with VBA see this page.
Where do I paste the code that I find on the internet Code Examples that use DIRThere are four basic examples, 3 on this page and 4 in the example workbook:1) Merge a range from all workbooks in a folder (below each other) 2) Merge a range from every workbook you select (below each other) 3) Merge a range from all workbooks in a folder (next to each other)4) Merge a range from all workbooks in a folder with Auto Filter The code will create a new workbook for you with the data from all workbooks with in column A or in row 1 the file name of the data in that row or column. The examples below are only working for one folder, there is no option for subfolders.
This master worksheet might also contain sales totals and averages, current inventory levels, and highest selling products for the entire enterprise.
Tip: If you frequently consolidate data, it might help to base your worksheets on a worksheet template that uses a consistent layout.
There is more code in this file but the macro we call is easier to edit. Value rnum = rnum Source Rcount End If End If mybook. There are a few things you must change before you can run the code Fill in the path to the folder Sub Basic_Example_3() Dim My Path As String, Files In Path As String Dim My Files() As String Dim Source Ccount As Long, Fnum As Long Dim mybook As Workbook, Base Wks As Worksheet Dim source Range As Range, destrange As Range Dim Cnum As Long, Calc Mode As Long 0 Then For Fnum = LBound(My Files) To UBound(My Files) Set mybook = Nothing On Error Resume Next Set mybook = Workbooks. Number With source Range Set destrange = destrange. Row On Error Go To 0 Case 2: On Error Resume Next RDB_Last = rng.
Download Merge FSOExamples.zip, you can also download the FSO code as TXT file. Close savechanges:=False End If Next Fnum Base Wks. Auto Fit End If Exit The Sub: And change the sheet and range to yours (see first example). Enable Events = False End With Save Drive Dir = Cur Dir Ch Dir Net "C:\Users\Ron\test" FName = Application. Open(My Path & My Files(Fnum)) On Error Go To 0 If Not mybook Is Nothing Then On Error Resume Next Set source Range = mybook. Find(What:="*", _ after:=rng.cells(1), _ Lookat:=xl Part, _ Look In:=xl Formulas, _ Search Order:=xl By Columns, _ Search Direction:=xl Previous, _ Match Case:=False).
Open arguments )will avoid the message do you want to update the links or not "0 Doesn't update any references"Use 3 instead of 0 if you want to update the links. Value rnum = rnum Source Rcount End If End If mybook. This example will filter a range on a worksheet in every workbook in the folder and copy the filter results to a new workbook.I just hit F9 to recalculate when I want to see the results. Status Bar = Loop Numso I can see the status of my macro and estimate how long there is left to calculate.Don’t forget to switch these back at the end of the macro!Many thanks to everyone who shared their tips & ideas with us.If you like the tips, please say thanks to the contributor.There are two ways to consolidate data: by Category or by Position.