Sort Worksheet Tabs Alphabetically

SKFireworks

New Member
Joined
Mar 13, 2018
Messages
4
I have documents with many tabs inside the worksheet and I would like to have the option to sort these tabs alphabetically. I have searched and tried adding the following module, but get an "Compile Error Syntex Error" I have the orriginal Document and could start over if needed. Any Help in this is appreciated.

After the Error Pop Up, I get another screen with the "Sub SortWorksheets()" highlighted in Yellow.

Below is the Module I am Using:

Sub SortWorksheets()


‘ sort worksheets in a workbook in ascending order


Dim sCount As Integer, i As Integer, j As Integer


Application.ScreenUpdating = False


sCount = Worksheets.Count


If sCount = 1 Then Exit Sub


For i = 1 To sCount – 1


For j = i + 1 To sCount


If Worksheets(j).Name < Worksheets(i).Name Then


Worksheets(j).Move Before:=Worksheets(i)


End If
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Sorry - This is the Whole Formula - The previous post was cut off.

Sub SortWorksheets()


‘ sort worksheets in a workbook in ascending order


Dim sCount As Integer, i As Integer, j As Integer


Application.ScreenUpdating = False


sCount = Worksheets.Count


If sCount = 1 Then Exit Sub


For i = 1 To sCount – 1


For j = i + 1 To sCount


If Worksheets(j).Name < Worksheets(i).Name Then


Worksheets(j).Move Before:=Worksheets(i)


End If


Next j


Next i


End Sub
 
Upvote 0
This line
Code:
For i = 1 To sCount – 1
has an N dash instead of a minus sign.
Try deleting it & replacing it with a proper - sign.
 
Upvote 0
This line
Code:
For i = 1 To sCount – 1
has an N dash instead of a minus sign.
Try deleting it & replacing it with a proper - sign.



Thank You - Additionally the error came up again and the following text is in RED on the equation:

‘ sort worksheets in a workbook in ascending order

Do you have any additional Advise?


Sub SortWorksheets()


‘ sort worksheets in a workbook in ascending order


Dim sCount As Integer, i As Integer, j As Integer


Application.ScreenUpdating = False


sCount = Worksheets.Count


If sCount = 1 Then Exit Sub


For i = 1 To sCount - 1


For j = i + 1 To sCount


If Worksheets(j).Name < Worksheets(i).Name Then


Worksheets(j).Move Before:=Worksheets(i)


End If


Next j


Next i


End Sub
 
Upvote 0
Missed that, you have the wrong type of quote/apostrophe it should be a '
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,474
Messages
6,125,025
Members
449,204
Latest member
LKN2GO

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