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
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

jiddings

Board Regular
Joined
Nov 22, 2008
Messages
135
Correction: code does not sort remaining sheets alphabetically.
How do I accomplish this also.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,324
Messages
5,600,956
Members
414,417
Latest member
Nobu

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