Macro for merging data from multiple sheets [Solved/Closed]

Report
-
TrowaD
Posts
2586
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 20, 2020
-
Hello,
I want to copy data of 2nd columns from all the sheets to different columns of single excel sheet. Is there any macro code available for performing this task?


1 reply

Posts
2586
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 20, 2020
389
Hi Ashwathi V K,

That single excel sheet in the code below is called "Main". Every Column B of all the other sheets will be copied to the "Main" sheets first available column based on the data in the first row.

Give it a try:
Sub RunMe()
Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Name <> "Main" Then
        ws.Select
        Columns("B:B").Copy Sheets("Main").Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)
    End If
Next ws
End Sub


Best regards,
Trowa
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 5430 users have said thank you to us this month

Sir,
It is not working. Is says 'Run time error 9' .

Thanking you
With regards
Ashwathi V K
TrowaD
Posts
2586
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 20, 2020
389
Hi Ashwathi,

Do you have a sheet named "Main" in your workbook?

Best regards,
Trowa
Hai Trowa,

Sorry , I didn't made a separate sheet named 'Main'. That's why it shows error. Now i am able to run. thankyou for solving the problem.

Thankyou

With regards
Ashwathi V K
TrowaD
Posts
2586
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 20, 2020
389 > ashwathi
No problem, happy to help you solve your query.