combine sheet1,sheet2,sheet3,sheet4,sheet5 into 1sheet

what I want is to combine sheet1,sheet2,sheet3,sheet4,sheet5 into 1sheet
so for the same
I have putted sheet1 ,sheet2,sheet3,sheet4,sheet5  all cells data in the same place after putting (,)
so all this I have to do by vba
Sample-file.xlsm
Avinash SinghAsked:
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.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may give this a try...


Sub CombineSheets()
Dim sws As Worksheet, dws As Worksheet
Dim lr As Long, lc As Long, i As Long, j As Long
Dim shArr, sh

Application.ScreenUpdating = False

Set dws = Sheets("Sheet6")
dws.Cells.Clear
lr = Sheets("Sheet1").UsedRange.Rows.Count
lc = Sheets("Sheet1").UsedRange.Columns.Count
Set sws = Sheets("Sheet1")
shArr = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")
ReDim Arr(1 To lr, 1 To lc)

For i = 1 To lr
    For j = 1 To lc
        For Each sh In shArr
            Set sws = Sheets(sh)
            If sws.Cells(i, j) <> "" Then
                If Arr(i, j) = "" Then
                    Arr(i, j) = sws.Cells(i, j)
                Else
                    Arr(i, j) = Arr(i, j) & "," & sws.Cells(i, j)
                End If
            End If
        Next sh
        Set sws = Nothing
    Next j
Next i
dws.Range("A1").Resize(lr, lc).Value = Arr
Application.ScreenUpdating = True
End Sub

Open in new window

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

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.