VBA Code to Alphabetize Between Two Tabs

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance as I'll try to post feedback.

How do I alphabetize the sheets that are between the "Start" and "End" sheets. I have sheets before Start and End, but I want them to stay where they are. Now what's happening is all the sheets are being alphabetized.

Code:
Sub Alp()

 '_______________________________________________________________________________________________
        'Turn on alerts, screen updates, and calculate
            'Turn On Display Alerts
                Application.DisplayAlerts = True

            'Turn on Screen Update
                Application.ScreenUpdating = True

            'Turn off Automatic Calculations
                Calculate


 Dim Sht_Start As Long
            Dim Sht_End As Long
            Dim i As Long
            Dim j As Long
            

'Alphabetize
            Sht_Start = Worksheets("Start").Index - 1
            Sht_End = Worksheets("End").Index - 1
            
            
            For i = Sht_Start To Sht_End
            
                    For j = Sht_Start To Sht_End - 1
                    
                        If UCase$(Application.Sheets(j).Name) > _
                            UCase$(Application.Sheets(j + 1).Name) Then
                            
                                Sheets(j).Move after:=Sheets(j + 1)
                                
                        End If
                        
                    Next
                    
                Next

 '_______________________________________________________________________________________________
        'Turn on alerts, screen updates, and calculate
            'Turn On Display Alerts
                Application.DisplayAlerts = True

            'Turn on Screen Update
                Application.ScreenUpdating = True

            'Turn off Automatic Calculations
                Calculate
                
                

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
VBA Code:
Sub AlphabetizeSheets()
Dim Sht_Start As Long, Sht_End As Long, i As Long, j As Long
Sht_Start = Worksheets("Start").Index
Sht_End = Worksheets("End").Index
Application.ScreenUpdating = False
For i = Sht_Start + 1 To Sht_End - 1
    For j = Sht_Start + 1 To Sht_End - 2
        If UCase$(Application.Sheets(j).Name) > _
            UCase$(Application.Sheets(j + 1).Name) Then
                Sheets(j).Move after:=Sheets(j + 1)
        End If
    Next j
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
@JoeMo that worked like a charm. Thanks so much and thanks for using as much of my original code as possible.
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,462
Members
448,899
Latest member
maplemeadows

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