View Single Post
 
Old 10-10-2015, 06:09 AM
Sandhya Sandhya is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Nov 2014
Posts: 21
Sandhya is on a distinguished road
Smile Merge the data from different excel files.

Hi Friends,

Kindly rectify the error in the below code.
it will consolidate the diffrerent excel file data into one single file.

error is getting into the below row.
______________________________

"ActiveSheet.Paste Destination = Worksheets("Sheet1"), Range(Cells(erow, 1), Cells(erow, 4))"

____________________

Sub copyDataFromMultipleWorkbooksintoMaster()
Dim FolderPath As String, filepath As String, filename As String
FolderPath = "c:\CONSOLIDATE\"
filepath = FolderPath & "*.xls*"
filename = Dir(filepath)
Dim lastrow As Long, lastcolumn As Long
Do While filename <> ""
Workbooks.Open (FolderPath & filename)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).Copy
Application.DisplayAlerts = False
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, 4))

filename = Dir
Loop
Application.DisplayAlerts = True


End Sub
Reply With Quote