Sort tab in A-Z order xl 2003

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi all,

Quite a simple question want to arrange sheets into A-Z order vba or not what ever is easiest.

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Code:
Sub SortSheets(Optional wkb As Workbook = Nothing, _</SPAN></SPAN>
               Optional ByVal iBeg As Long = 1, _</SPAN></SPAN></SPAN>
               Optional ByVal iEnd As Long = 2147483647)</SPAN></SPAN></SPAN>
    ' shg 2009-09</SPAN></SPAN></SPAN>
    ' Insertion-sorts sheets from iBeg to iEnd</SPAN></SPAN></SPAN>
 
    Dim i           As Long</SPAN></SPAN></SPAN>
    Dim j           As Long</SPAN></SPAN></SPAN>
 
    If wkb Is Nothing Then Set wkb = ActiveWorkbook</SPAN></SPAN></SPAN>
 
    With wkb</SPAN></SPAN></SPAN>
        If iBeg < 1 Then iBeg = 1</SPAN></SPAN></SPAN>
        If iEnd > .Sheets.Count Then iEnd = .Sheets.Count</SPAN></SPAN></SPAN>
 
        For i = iBeg + 1 To iEnd</SPAN></SPAN></SPAN>
            For j = iBeg To i - 1</SPAN></SPAN></SPAN>
                If StrComp(.Sheets(i).Name, .Sheets(j).Name, vbTextCompare) <> 1 Then</SPAN></SPAN></SPAN>
                    .Sheets(i).Move Before:=.Sheets(j)</SPAN></SPAN></SPAN>
                    Exit For</SPAN></SPAN></SPAN>
                End If</SPAN></SPAN></SPAN>
            Next j</SPAN></SPAN></SPAN>
        Next i</SPAN></SPAN></SPAN>
    End With</SPAN></SPAN></SPAN>
End Sub</SPAN></SPAN></SPAN>

E.g.

Code:
SortSheets ThisWorkbook
 
Upvote 0
Thanks shg for the help.

Wigi I searched on google and the codes seemed very complained and long just wanted to ask if anyone knew any code that was easier. FYI

Many thanks
 
Upvote 0
You're welcome, glad it helped.
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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