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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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