How to Sort Excel Sheets from Multiple Excel files in one folder

mr.vasanth18

New Member
Joined
Dec 6, 2011
Messages
19
Hi All,

I have multiple excel workbook ( 85) in one folder. Each workbook contain 13 sheets has same names with different order. Only Excel workbook name is different. Now I want to assign all workbook sheets in one order. Kindly note Its not assent or dissenting order. I had listed all workbook name with each sheets name using power query. Could you please provide any VBA for this, .

Ex
See the sample pic I had attached . If you need more details kindly ask me
sample.png
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Assuming the workbook running the code will be In the same folder as the 85 to be reorganized.

VBA Code:
Sub t()
Dim fPath As String, fName As String, sh As Worksheet, wb As Workbook, ary As Variant
ary = Array("Unit", "Area", "Filed", "Location", "Group", "Main", "Material", "Part", "Design", "Cost", "Outboard", "Temporary", "Final")
fPath = ThisWorkbook.Path & "\"
fName = Dir(fPath & "*.xls*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
        Set wb = Workbooks.Open(fPath & fName)
            For i = LBound(ary) To UBound(ary) - 1
                On Error Resume Next
                    Sheets(ary(i + 1)).Move After:=Sheets(ary(i))
                On Error GoTo 0
                Err.Clear                
            Next
            wb.Close True
       End If
       fName = Dir
    Loop
End Sub
 
Upvote 0
Same idea using FSO.

VBA Code:
Sub ARRANGE()
Application.ScreenUpdating = False
Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Fold As Object: Set Fold = FSO.getfolder("C:\Users\USERNAME\Desktop\Files")
Dim wb As Workbook
Dim AR() As Variant: AR = Array("Unit", "Area", "Filed", "Location", "Group", "Main", "Material", "Part", "Design", "Cost", "Outboard", "Temporary", "Final")

For Each xlFile In Fold.Files
    Set wb = Application.Workbooks.Open(xlFile)
    For i = 0 To UBound(AR)
        wb.Sheets(AR(i)).Move before:=Sheets(i + 1)
    Next i
    wb.Close True
Next xlFile

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Assuming the workbook running the code will be In the same folder as the 85 to be reorganized.

VBA Code:
Sub t()
Dim fPath As String, fName As String, sh As Worksheet, wb As Workbook, ary As Variant
ary = Array("Unit", "Area", "Filed", "Location", "Group", "Main", "Material", "Part", "Design", "Cost", "Outboard", "Temporary", "Final")
fPath = ThisWorkbook.Path & "\"
fName = Dir(fPath & "*.xls*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
        Set wb = Workbooks.Open(fPath & fName)
            For i = LBound(ary) To UBound(ary) - 1
                On Error Resume Next
                    Sheets(ary(i + 1)).Move After:=Sheets(ary(i))
                On Error GoTo 0
                Err.Clear               
            Next
            wb.Close True
       End If
       fName = Dir
    Loop
End Sub

Thank you so much.
 
Upvote 0
Same idea using FSO.

VBA Code:
Sub ARRANGE()
Application.ScreenUpdating = False
Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Fold As Object: Set Fold = FSO.getfolder("C:\Users\USERNAME\Desktop\Files")
Dim wb As Workbook
Dim AR() As Variant: AR = Array("Unit", "Area", "Filed", "Location", "Group", "Main", "Material", "Part", "Design", "Cost", "Outboard", "Temporary", "Final")

For Each xlFile In Fold.Files
    Set wb = Application.Workbooks.Open(xlFile)
    For i = 0 To UBound(AR)
        wb.Sheets(AR(i)).Move before:=Sheets(i + 1)
    Next i
    wb.Close True
Next xlFile

Application.ScreenUpdating = True
End Sub
Thanks you SO much. I can use this both VBA. Thanks lot
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top