Sorting worksheets?

jiddings

Board Regular
Joined
Nov 22, 2008
Messages
135
The following code does work by placing SUMMARY, MASTER, & INSTRUCTIONS in the right and sorting remaining sheets alphabetically.

However, how do I modify the following code to sort the worksheets so the SUMMARY sheet is first (on left) and MASTER sheet followed by INSTRUCTIONS are the last two sheets on the right? Sorting the remaining sheets alphabetically inbetween SUMMARY and MASTER sheets.

I've tried several changes and can't get it to work as desired.


Sub SortALLSheets()
'sort sheets within a workbook in Excel
Dim iSheet As Long, iBefore As Long
WksName = "SUMMARY"
WksName = "MASTER"
WksName = "INSTRUCTIONS"
For iSheet = 1 To ActiveWorkbook.Sheets.Count
Sheets(iSheet).Visible = True
For iBefore = 1 To iSheet - 1
If Sheets(iBefore).Name <> Sheets(iSheet).Name Then
ActiveWorkbook.Sheets(iSheet).Move Before:=ActiveWorkbook.Sheets(iBefore)
Exit For
End If
Next iBefore
Next iSheet
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Correction: code does not sort remaining sheets alphabetically.
How do I accomplish this also.
 
Upvote 0

Forum statistics

Threads
1,222,017
Messages
6,163,411
Members
451,835
Latest member
kristianb63

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