copy all 4 sheets data and paste to sheet5

I want to copy data from sheet1,sheet2,sheet3,sheet4 and paste the data to sheet5
copy all 4 sheets data and paste to sheet5
kindly see sheet5
this highlighted colour is only for understanding purpose
Avinash SinghAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this. I am assuming the order of Names is same in all the worksheets.
Sub CopyData()
Dim ShArr, Sh
Dim dws As Worksheet, ws As Worksheet
Dim lr As Long, lc As Long, i As Long, dlc As Long

Application.ScreenUpdating = False

Set dws = Sheets("Sheet5")
ShArr = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4")
For Each Sh In ShArr
    Set ws = Sheets(Sh)
    lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
    If dws.Range("A1").Value = "" Then ws.Range("A2:A" & lr).Copy dws.Range("A1")
    For i = 2 To lr
        lc = ws.Cells(i, Columns.Count).End(xlToLeft).Column
        If lc > 1 Then
            dlc = dws.Cells(i - 1, Columns.Count).End(xlToLeft).Column + 1
            ws.Range("B" & i, ws.Cells(i, lc)).Copy dws.Cells(i - 1, dlc)
        End If
    Next i
Next Sh
Application.ScreenUpdating = True
End Sub

Open in new window

In the attached, you can click the button called "Get All Data" on Sheet5 to run the code.

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
Avinash SinghAuthor Commented:
Thnx Neeraj sir for giving ur precious time to this post
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Avinash!
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
Microsoft Office

From novice to tech pro — start learning today.