Macro to open Mulyiple Files and copy one below each other

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,585
Office Version
  1. 2021
Platform
  1. Windows
I have the following code to allow the user to select one file at a time and to copy and paste the data after the last row containing data


I would like this amended so as to allow the user to select multiple files and the macro to copy and paste the data from each of these files

your assistance in this regard is most appreciated




Code:
 Sub Open_Workbook()
ChDir ("C:\Sales Reports")
A:
Dim A     As Variant
Dim LR As Long
  


If msg <> "" Then MsgBox msg

     A = Application.GetOpenFilename
    If A = False Or IsEmpty(A) Then Exit Sub
    
    Application.ScreenUpdating = False
     
    
  
    
   With Workbooks.Open(A)
     msg = msg & vbCr & A
     
        With Sheets(1)
            .Range("a1", .Range("J" & Rows.Count).End(xlUp)).Copy _
                Destination:=ThisWorkbook.Sheets("Data Import").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End With
      
        .Close SaveChanges:=False
    End With
   answer = MsgBox("Does another file needs to be selected?", vbYesNo + vbQuestion, "Hello")
If answer = vbYes Then
GoTo A:
End If
 Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Untested, but the parts to change should be something like this:
Code:
    A = Application.GetOpenFilename(MultiSelect:=True)
    If TypeName(A) = "Boolean" Then Exit Sub
    
    Dim file As Variant
    For Each file In A
        With Workbooks.Open(file)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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