I Am getting an error 1004 Application-defined or object-defined . please answer me how to remove this error and execute my programe.

My code is:
In Module 1-

Sub copyDataFromMultipleWorkbook()
Dim FolderPath As String
Dim Filepath As String, Filename As String
FolderPath = "C:\Myprg\"

Filepath = "*data1.xlsx*"

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

In Module 2-

Sub cpyDataFromMultipleWorkbook()

Dim FolderPath As String
Dim Filepath As String, Filename As String

FolderPath = "C:\Myprg\"

Filepath = "*data2.xlsx*"

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 = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet2").Range(Cells(erow, 1), Cells(erow, 4))

Filename = Dir

Loop
Application.DisplayAlerts = True
End Sub
rimmyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rimmyAuthor Commented:
Please solve my problem:
error 1004 (Application defined or Object defined error)
My code:
In Module1:

Sub copyDataFromMultipleWorkbook()
Dim FolderPath As String
Dim Filepath As String, Filename As String
FolderPath = "C:\Myprg\"

Filepath = "*data1.xlsx*"

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

In Module 2:

Sub cpyDataFromMultipleWorkbook()

Dim FolderPath As String
Dim Filepath As String, Filename As String

FolderPath = "C:\Myprg\"

Filepath = "*data2.xlsx*"

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 = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet2").Range(Cells(erow, 1), Cells(erow, 4))

Filename = Dir

Loop
Application.DisplayAlerts = True
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rimmyAuthor Commented:
please  reply soon I don't Know how remove this error.
The Programe is I want to copy : File1 to sheet1 of master file &
                                                           File2 to sheet2 of Master file.
My error is comming here
ActiveSheet.Paste Destination:=Worksheets("Sheet2").Range(Cells(erow, 1), Cells(erow, 4))

=> i wrote thi code also:
Private Sub Workbook_Open()

copyDataFromMultipleWorkbook
 
    cpyDataFromMultipleWorkbook

End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.