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
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