Alphabetizing Worksheets

G

geigersc

I have used a program by someone else that is supposed to alphabetize my
worksheets. Unfortunately I'm not sure how to debug the code. This is a
portion of what I have:

'''''''''''''''''''''''''''''''''''''''''''''''
' If First and Last are both 0, sort all sheets.
''''''''''''''''''''''''''''''''''''''''''''''
If (FirstToSort = 0) And (LastToSort = 0) Then
FirstToSort = 1
LastToSort = WB.Worksheets.Count
Else
'''''''''''''''''''''''''''''''''''''''
' More than one sheet selected. We
' can sort only if the selected
' sheet are adjacent.
'''''''''''''''''''''''''''''''''''''''
B = TestFirstLastSort(FirstToSort, LastToSort, ErrorText)
If B = False Then
SortWorksheetsByName = False
Exit Function
End If
End If

When I "debug" I get the following message:

Compile Error:
Sub or Function not defined

Do you need to know more to help me? I'm a little clueless, to say the
least on this. I've tried looking at different sites, but without totally
understanding the coding, I'm not sure what I'm looking for, or how to cure
the issue.

Thank you for your help... in advance. A lot of you guys/gals on here that
help are VERY much appreciated.
 
J

johnmanivong

I have used a program by someone else that is supposed to alphabetize my
worksheets.  Unfortunately I'm not sure how to debug the code.  This is a
portion of what I have:

'''''''''''''''''''''''''''''''''''''''''''''''
' If First and Last are both 0, sort all sheets.
''''''''''''''''''''''''''''''''''''''''''''''
If (FirstToSort = 0) And (LastToSort = 0) Then
    FirstToSort = 1
    LastToSort = WB.Worksheets.Count
Else
    '''''''''''''''''''''''''''''''''''''''
    ' More than one sheet selected. We
    ' can sort only if the selected
    ' sheet are adjacent.
    '''''''''''''''''''''''''''''''''''''''
    B = TestFirstLastSort(FirstToSort, LastToSort, ErrorText)
    If B = False Then
        SortWorksheetsByName = False
        Exit Function
    End If
End If

When I "debug" I get the following message:

Compile Error:
Sub or Function not defined

Do you need to know more to help me?  I'm a little clueless, to say the
least on this.  I've tried looking at different sites, but without totally
understanding the coding, I'm not sure what I'm looking for, or how to cure
the issue.

Thank you for your help... in advance.  A lot of you guys/gals on here that
help are VERY much appreciated.

Try this

Option Explicit

--------------------------------------------------------------------------------

Sub SortingWks()
Dim i As Long
Dim j As Long
For i = 1 To Worksheets.Count
j = i
Do While j > 1
If Worksheets(j).Name < Worksheets(j - 1).Name Then
Worksheets(j).Move Before:=Worksheets(j - 1)
End If
j = j - 1
Loop
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top