I’m hoping you could help me and point me in the right direction;
I’m currently working on a code that would help me to select and open to workbooks and copy the all the information in each workbook and paste into in the main workbook sheet called “Data”.
I looking for the search and open file option instead of the file folder location option so any user can search and select the workbook;
The current code is stopping when selecting the main workbook to activate and paste the copied data of the active woorkbook which is one of the two previously selected;
The code i’m trying:
Option Explicit
Sub opening_multiple_file()
Dim wb As ThisWorkbook, wb2 As Workbook, wb3 As Workbook
Dim ws As Worksheet
Dim i As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "Excel Files", "*.xls*"
If .Show = True Then
For i = 1 To .SelectedItems.Count
Workbooks.Open .SelectedItems(i)
Next i
End If
End With
Set wb2 = ActiveWorkbook
wb2.Activate
wb2.Worksheets("Data").Range("D1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wb.Activate
wb.Worksheets("data").Range("D1").Select
ActiveSheet.Paste
wb.Activate
ActiveWindow.Close
Set wb3 = ActiveWorkbook
wb3.Activate
wb3.Worksheets("Data").Range("D1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wb.Activate
wb.Worksheets("data").Range("D1").Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveSheet.Paste
wb.Activate
ActiveWindow.Close
End Sub
Marco HV is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.