PDA

View Full Version : code for copying from multiple files and paste in master file



Veeru
09-15-2017, 12:31 PM
Hi,

I looking for a solution ,where by running a code we can copy data from 7 different files and paste in master file in their respective 7 tabs.

we can store all these 8 files in one folder and code can identify files from this folder and paste in master file in that particular tab.

Any help will be appreciated .

Please note we don't want to just combine these 7 sheets into one workbook. we want to copy and paste only.

Thank you very much

jolivanes
09-15-2017, 01:03 PM
their respective 7 tabs.
1 Tab (= Sheet) per workbook? If so, what are the names of these sheets? Or do these workbooks just have the one sheet?

What are the names of the sheets to be pasted into? How are these sheet names relevant to the sheets where the data is copied from?

This might be one possibility.

Sub Copy_Only_From_First_Sheet()
Dim wb As String, i As Long, sh As Worksheet
Application.ScreenUpdating = False
i = 2
wb = Dir(ThisWorkbook.Path & "\*")
Do Until wb = ""
If wb <> ThisWorkbook.Name Then
Workbooks.Open ThisWorkbook.Path & "\" & wb
Workbooks(wb).Sheets(1).UsedRange.Copy ThisWorkbook.Sheets(i).Cells(Rows.Count, 1).End(xlUp).Offset(1)
Workbooks(wb).Close False
End If
wb = Dir
i = i + 1
Loop
Application.ScreenUpdating = True
End Sub