Hi
Like This
file path in" K2 down sheets Data
VBA Code:
Sub selected_Workbooks()
Dim wbk As Workbook
Dim a, MyFiles As Variant
Dim lr, i As Double
Dim fPath As Variant
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("Data").[A:G].ClearContents
fPath = Sheets("Data").Range("k2:k" & Cells(Rows.Count, "k").End(xlUp).Row).Value
For i = 1 To UBound(fPath)
Set wbk = Workbooks.Open(Filename:=fPath(i, 1))
a = wbk.Sheets("Summary").UsedRange.Columns("A:G").Value
wbk.Close savechanges:=True
lr = Sheets("Data").Cells(Sheets("Data").Rows.Count, "b").End(xlUp).Row
If lr = 1 Then
Cells(lr, 1).Resize(UBound(a, 1), UBound(a, 2)) = a
Else
Cells(lr + 1, 1).Resize(UBound(a, 1), UBound(a, 2)) = a
End If
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Hi. Thanks for the updated code. However, it didn't work. I have written a code that seems to do the job. At the moment it is using the clipboard to do copy and paste. I tried assigning values but couldn't get it work. The copy option works but copies data across as formulas, I would like only values. Any ideas?
Private Sub CommandButton1_Click()
Dim sFile As String, myPath As String
Dim wbSource As Workbook
Dim wsSource As Worksheet, wsTarget As Worksheet
Dim scell As Range
Dim lrow As Long, ldestrow As Long
Dim rgSource As Range, rgDestination As Range
'optimise macro speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'set target worksheet
Set wsTarget = Sheets("Data")
'clear existing contents in target sheet
wsTarget.Cells.Clear
myPath = Range("D6") & Application.PathSeparator
'loop through the excel files in the folder
sFile = Dir(myPath & "*.xlsx")
Do While sFile <> ""
'open the source file and set source worksheet
Set wbSource = Workbooks.Open(myPath & sFile, ReadOnly:=True)
Set wsSource = wbSource.Worksheets("Summary")
Set scell = wsSource.Range("A1")
'find last row in source data
lrow = wsSource.Cells(wsSource.Rows.Count, scell.Column).End(xlUp).Row
Set rgSource = wsSource.Range(scell, wsSource.Cells(lrow, 7))
'find first blank row in target worksheetbasedon data in column A
'offset property moves down 1 row
ldestrow = wsTarget.Cells(wsTarget.Rows.Count, "A").End(xlUp).Offset(1).Row
Set rgDestination = wsTarget.Range("A" & ldestrow)
'copy and paste data
'wsSource.Range(scell, wsSource.Cells(lrow, 7)).Copy wsTarget.Range("A" & ldestrow)
'rgDestination.Value = rgSource.Value - not working
'Set rgDestination = rgDestination.Resize(rgSource.Rows.Count, rgSource.Columns.Count)
rgSource.Copy
rgDestination.PasteSpecial xlPasteValues
'close the source workbook
Application.DisplayAlerts = False
wbSource.Close savechanges:=False
'Get nextfile
sFile = Dir()
Loop
'reset settings
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub