Hi,
I need some assistance with modifying the code below. Currenlty the code loops through workbooks andn worksheets in a folder, copies its data and appends it to the master file. I would like to modify the path code to only copy and append data to the master file from currently open workbook.
Any help would be greatly appreciated.
Option Explicit Sub ConsolidateData() Dim myPath As String Dim SumPath As String Dim MyName As String Dim SumName As String Dim MyTemplate As String Dim SumTemplate As String Dim myWS As Worksheet Dim sumWS As Worksheet Dim Last_Row As Long 'Define folders and filenames myPath = "Path\" SumPath = "master folder\" MyTemplate = "*.xls" 'Set the template. SumTemplate = "Master.xlsm" 'Open the master file and get the Worksheet to put the data into SumName = Dir(SumPath & SumTemplate) Workbooks.Open SumPath & SumName On Error Resume Next Set sumWS = ActiveWorkbook.Worksheets("Sheet1") 'Open each source file, copying the data from each into the template file MyName = Dir(myPath & MyTemplate) 'Retrieve the first file Do While MyName <> "" 'Open the source file and get the worksheet with the data we want. Workbooks.Open myPath & MyName Set myWS = ActiveWorkbook.Worksheets("Sheet1") 'Copy the data from the source and paste at the end of Summary sheet 'myWS.Range("A2:Z100").Copy 'Selects data until last row and copies it With myWS.Range("A2") Range(.Cells(1, 1), .End(xlDown).Cells(1, 21)).Copy End With sumWS.Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues ActiveCell.Copy 'Suppresses the clipboard data prompt; since it only appears when large data set is copied 'Close the current sourcefile and get the next Workbooks(MyName).Close SaveChanges:=False 'close MyName = Dir 'Get next file Loop Set sumWS = ActiveWorkbook.Worksheets("Sheet2") 'Open each source file, copying the data from each into the template file MyName = Dir(myPath & MyTemplate) 'Retrieve the first file Do While MyName <> "" 'Open the source file and get the worksheet with the data we want. Workbooks.Open myPath & MyName Set myWS = ActiveWorkbook.Worksheets("Sheet2") 'Selects data until last row and copies it With myWS.Range("A2") Range(.Cells(1, 1), .End(xlDown).Cells(1, 21)).Copy End With sumWS.Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues ActiveCell.Copy 'Suppresses the clipboard data prompt; since it only appears when large data set is copied 'Close the current sourcefile and get the next Workbooks(MyName).Close SaveChanges:=False 'close MyName = Dir 'Get next file Loop End Sub