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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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
 

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
3,093
Office Version
  1. 365
Platform
  1. Windows
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
 

mr.vasanth18

New Member
Joined
Dec 6, 2011
Messages
19
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.
 

mr.vasanth18

New Member
Joined
Dec 6, 2011
Messages
19
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
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
You're welcome,
Regards, JLG
 

Watch MrExcel Video

Forum statistics

Threads
1,127,205
Messages
5,623,363
Members
415,969
Latest member
Rey99

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
Top