Jambi46n2
Active Member
- Joined
- May 24, 2016
- Messages
- 260
- Office Version
- 365
- Platform
- Windows
I have 150 sheets inside 1 workbook, they need to be ordered exactly as listed in a column on a separate sheet.
Example (SheetA, SheetB, SheetC, ect)
These sheets have been renamed, and every macro I've found online is re-ordering based on the "Sheets Property (Name)" not by the actual naming convention listed in Excel.
I was hoping the code below would work, but it shorts by the property of the sheet, not the actual sheet name.
Any suggestions are greatly appreciated.
Thank you!
Example (SheetA, SheetB, SheetC, ect)
These sheets have been renamed, and every macro I've found online is re-ordering based on the "Sheets Property (Name)" not by the actual naming convention listed in Excel.
I was hoping the code below would work, but it shorts by the property of the sheet, not the actual sheet name.
Any suggestions are greatly appreciated.
Thank you!
Code:
Sub SortWS()
' Assumes Source Listing is Already sorted
' If source Listing is not sorted additional coding will be
' needed to sort the source listing first
' There is no error checking so if the sheet name does not match the source list
' you will get an error if it attempts to move a sheet that doesnt exist
Dim ActiveWB As String
ActiveWB = ActiveWorkbook.Name 'Capture Active Workbook Name
Dim SourceWB As Workbook
Dim SourceSH As String
Application.ScreenUpdating = False 'Turn ScreenUpdating OFf so its transparent
Set SourceWB = Workbooks.Open("F:\Finance Projects\BizNet Report\Chris\lists.xlsx", False, True) 'Set the Source workbook Change the file Location
SourceSH = "Sheet1" 'Set the Source Sheet Name
LastRow = SourceWB.Worksheets(SourceSH).Cells(Rows.Count, "A").End(xlUp).Row 'Determines Last Row based on column A if the names are a different column change A to appropriate column
ReDim SheetNames(LastRow) 'Sets Array based on Number of Sheets
For T = 1 To LastRow
SheetNames(T) = SourceWB.Worksheets(SourceSH).Cells(T, 1) 'Read the sheet names in based on the Sourcesheet. Assumes names are in Column A on source sheet Change the 1 to appropriate column
Next T
SourceWB.Close False ' close the source workbook without saving changes
Workbooks(ActiveWB).Activate 'Make Sure workbook is active
Application.ScreenUpdating = True 'Turn Screen Updating on
For I = 1 To LastRow
For T = I To LastRow
If SheetNames(T) < Worksheets(I).Name Then Worksheets(SheetNames(T)).Move Before:=Worksheets(I)
Next T
Next I
End Sub
Last edited: