Sort Excel Worksheets in a workbook based on order of names outlined

vik2slick

New Member
Joined
Dec 28, 2017
Messages
23
Hi, Can anyone help in providing a VBA code to sort Excel Worksheets in a workbook based on an order of worksheet names outlined in a 'Order' worksheet that has the names listed in cell range A2 to A200?

Appreciate the help.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Code:
Sub SortSheets()
  Dim lngCounter As Long
  Dim objSheet As Object
  Dim x As Range
  
  For Each x In ThisWorkbook.Sheets("Order").Range("A2:A200")
    On Error Resume Next
    Set objSheet = ThisWorkbook.Sheets(x.Text)
    On Error GoTo 0
    If Not objSheet Is Nothing Then
      lngCounter = lngCounter + 1
      objSheet.Move ThisWorkbook.Sheets(lngCounter)
      Set objSheet = Nothing
    End If
  Next x
End Sub
 
Upvote 0
Thank you so much!! This worked and saves me so much time for multiple files on a monthly basis. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,134
Members
449,206
Latest member
burgsrus

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