Copy data from a defined sheet in multiple workbooks into a sheet named Detail of another workbook

suikt

New Member
Joined
Apr 12, 2018
Messages
2
Dear All,

I have about 21 files likes 1,2,3,4 as attached - in these workbooks, have many sheets but will have one sheet named "ABC" which is same to all 21 files.

I have another Macro workbooks with many worksheets. I wish to consolidate the above data at "ABC" into only one worksheet named "Detail".

I wish to select the files to consolidate.

Below is the code I have searched but it does not work. Please help me!

Sub ConsolidateData()
Dim Item, Arr(), lR As Long
Dim Wb As Workbook, Ws As Worksheet, MainWb As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
Set MainWb = ThisWorkbook.Sheets("Detail")
MainWb.Range("A6:R65000").ClearContents

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Add "Microsoft Excel Files", "*.xls*", 1

If Not .Show = -1 Then MsgBox "No files selected", vbCritical, "GPE": Exit Sub

For Each Item In .SelectedItems
Set Wb = Workbooks.Open(Item)
Arr() = Wb.Sheets("ABC").Range("A3:R1000").Value
With MainWb
lR = .Range("D" & Rows.Count).End(xlUp).Row + 1
.Range("A" & lR).Resize(, 1099) = Arr
End With
Wb.Close False
Next Item
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True

Set MainWb = Nothing
MsgBox "Done", vbInformation, "GPE"
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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