I have made some changes...
and its working now..
Sub MergeAll()
Dim MainSh As Worksheet
Dim SubSh As Worksheet
Dim SearchIn As Range
'Clearing Previous data
For Each sh In ThisWorkbook.Sheets
sh.Cells(1, 0).CurrentRegion.Offset(1, 1).Clear
Next
Application.ScreenUpdating = False
Application.StatusBar = "Please Wait...."
FPath = "C:\Documents and Settings\Administrator\Desktop\Vikas Gautam xlfiles\Extracts\Extracts"
MainBook = ThisWorkbook.Name
FName = Dir(FPath & "\" & "*.xl*")
Do While FName <> ""
Workbooks.Open (FPath & "\" & FName)
For Each MainSh In Workbooks(MainBook).Sheets
temp = MainSh.Name
lr = MainSh.Cells(1, 1).CurrentRegion.Rows.Count + 1
For Each SubSh In Workbooks(FName).Sheets
If MainSh.Name = SubSh.Name And SubSh.Name <> "Summary" Then
SubSh.Select
Set SearchIn = Cells(1, 1).CurrentRegion.Rows(1).Offset(0, 1)
SearchIn.Select
For c = 2 To MainSh.UsedRange.Columns.Count
ColFnd = Application.Match(MainSh.Cells(1, c), SearchIn, 0) + 1
If Not IsError(ColFnd) Then
SubSh.Range(Cells(2, ColFnd), Cells(SubSh.UsedRange.Rows.Count, ColFnd)).Copy MainSh.Cells(lr, c)
End If
Next
End If
Next
Next
Workbooks(FName).Close False
FName = Dir
wb = wb + 1
Application.StatusBar = "Please Wait.... " & wb & " workbooks done..! "
DoEvents
Loop
Application.ScreenUpdating = True
Application.StatusBar = ""
MsgBox "Finished", vbInformation
End Sub
Bookmarks