ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Alphabetizing Worksheets (https://www.excelbanter.com/excel-programming/406578-alphabetizing-worksheets.html)

geigersc

Alphabetizing Worksheets
 
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.

Gary''s Student

Alphabetizing Worksheets
 
http://www.cpearson.com/excel/sortws.aspx
--
Gary''s Student - gsnu200770

[email protected]

Alphabetizing Worksheets
 
On Feb 24, 6:52*am, geigersc
wrote:
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 Befo=Worksheets(j - 1)
End If
j = j - 1
Loop
Next
End Sub


All times are GMT +1. The time now is 12:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com