Dear All,
I am not that much familier with VBA. i am getting error as Run Time error '1004' Microsoft excel cannot paste the data in following VBA code.
Sub copydata()
Dim folderpath As String, filepath As String, filename As String
folderpath = "C:\Users\09395\Desktop\Final CFCM\"
filepath = folderpath & "*.xls*"
filename = Dir(filepath)
Dim lastrow As Long, lastcoloumn 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, 47))
filename = Dir
Loop
Application.DisplayAlerts = True
End Sub
Bookmarks