I have to copy data from 100+ workbooks and paste it into a master workbook. All the workbooks are located in a folder on my desktop: C:\Users\brw20\Desktop\Project XYZ\Updated\
All the workbooks contain a sheet named ‘Mutation', I have to open each workbook, go to sheet 'Mutation’, select columns range A to J starting from row 3 to row ‘x'(the last row can vary in each workbook). In the master worksheet, I paste the data in Columns A to J and continue pasting/appending the data as I copy data from more workbooks. The code given below I tried has fixed no. of rows due to which pop up generates(“There is large amount of information on clipboard. Do you want to be able to paste this information into another program later.”) against each copying sheet. So, I was wondering if someone could please help me to create a VBA code for this which copy only fixed columns but variable rows? I'm really new to VBA and would really appreciate your help!
Please let me know if you require any clarification.
Many thanks! =)
Sub LoopThroughDirectory()
Dim MyFile As String
Dim wb As Workbook
Dim ws As Worksheet
sPath = "C:\Users\brw20\Desktop\Project XYZ\Updated\"
Dim erow
MyFile = Dir(sPath & "*.xlsx")
Application.ScreenUpdating = False
Do While MyFile <> ""
If MyFile = "zmaster.xlsm" Then
Exit Sub
End If
Workbooks.Open (sPath & MyFile)
'Set ws = wb.Sheets(2)
Worksheets("Mutation").Range("A3:J1000").Copy
'Call CopyValues(Sheet1.Range("A1:B12"), Sheet1.Range("A1:B12"))
ActiveWorkbook.Close
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 1))
'Workbooks.Open ThisWorkbook.Path & "\DgetData.xls"
MyFile = Dir
Loop
End Sub