Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default re-order worksheets by sheet name

I often need to organize worksheets in a workbook left to right,
alphabetically by sheet name. Is there a way to automate this process?

As an added bonus, it would also be helpful if I could organize only
selected sheets alphabetically.

Thanks!
Julia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default re-order worksheets by sheet name

'================================================= ====
Sub WorksheetSort()
'sort worksheets in a workbook
' 07/02/2000 - included hidden sheets in sort and return to
' sheet that was active at start of sort
' 10/24/2000 - added GetChoices form per J.Walkenbach
' This procedure used function GETCHOICES in Mod_ChoicesForm
' written by Gary L. Brown -
'
On Error GoTo err_WorksheetSort
Dim aryHiddensheets, aryChoices(1 To 2)
Dim i As Integer, x As Integer, iWksheetCount As Integer
Dim iWorksheets As Integer, y As Integer
Dim strWorksheetName As String
Dim varAnswer As Variant

'----------Set up Choices----------------
aryChoices(1) = "Ascending"
aryChoices(2) = "Descending"
'----------------------------------------

'get choice (call GetChoice function - Mod_ChoicesForm)
varAnswer = GetChoice(aryChoices, 1, "Worksheet Sort...")

If varAnswer = False Then
MsgBox "Worksheet sort has been canceled....", _
vbExclamation, "WARNING..."
Exit Sub
End If

'Count number of worksheets in workbook and get sheet name
iWorksheets = ActiveWorkbook.Sheets.Count
strWorksheetName = Application.ActiveSheet.name

'redim array
ReDim aryHiddensheets(1 To iWorksheets)

'put hidden sheets in an array, then unhide the sheets
For x = 1 To iWorksheets
If Worksheets(x).Visible = False Then
aryHiddensheets(x) = Worksheets(x).name
Worksheets(x).Visible = True
End If
Next

iWksheetCount = Application.ActiveWorkbook.Worksheets.Count

For i = 1 To iWksheetCount
For x = i To iWksheetCount
If varAnswer = 1 Then
If UCase(Worksheets(x).name) < _
UCase(Worksheets(i).name) Then
Worksheets(x).Move Befo=Worksheets(i)
End If
End If
If varAnswer = 2 Then
If UCase(Worksheets(x).name) _
UCase(Worksheets(i).name) Then
Worksheets(x).Move Befo=Worksheets(i)
End If
End If
Next x
Next i

HideAndExit:
're-hide previously hidden sheets
On Error Resume Next
y = UBound(aryHiddensheets)
For x = 1 To y
Worksheets(aryHiddensheets(x)).Visible = False
Next

Application.Worksheets(strWorksheetName).Activate

exit_WorksheetSort:
Exit Sub

err_WorksheetSort:
MsgBox "Error: " & Err & " - " & Err.Description
Resume exit_WorksheetSort

End Sub
'================================================= ====


"Julia Chromicz" wrote:

I often need to organize worksheets in a workbook left to right,
alphabetically by sheet name. Is there a way to automate this process?

As an added bonus, it would also be helpful if I could organize only
selected sheets alphabetically.

Thanks!
Julia

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default re-order worksheets by sheet name

Take a look he

http://cpearson.com/excel/sortws.htm

In article ,
"Julia Chromicz" wrote:

I often need to organize worksheets in a workbook left to right,
alphabetically by sheet name. Is there a way to automate this process?

As an added bonus, it would also be helpful if I could organize only
selected sheets alphabetically.

Thanks!
Julia

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default re-order worksheets by sheet name

Thanks! That's what I needed.

-Julia

"JE McGimpsey" wrote:

Take a look he

http://cpearson.com/excel/sortws.htm

In article ,
"Julia Chromicz" wrote:

I often need to organize worksheets in a workbook left to right,
alphabetically by sheet name. Is there a way to automate this process?

As an added bonus, it would also be helpful if I could organize only
selected sheets alphabetically.

Thanks!
Julia


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default re-order worksheets by sheet name

Julia,

Chip Pearson has a macro to sort worksheets.
http://www.cpearson.com/excel/sortws.htm

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Julia Chromicz" wrote in message
...
I often need to organize worksheets in a workbook left to right,
alphabetically by sheet name. Is there a way to automate this process?

As an added bonus, it would also be helpful if I could organize only
selected sheets alphabetically.

Thanks!
Julia



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the order of worksheets matter ? kittronald Excel Worksheet Functions 1 August 20th 11 06:56 PM
Populate order sheet with data from work sheet Veronica Johnson Excel Worksheet Functions 4 January 22nd 08 03:29 AM
printing order of worksheets pkeegs Excel Discussion (Misc queries) 0 November 29th 06 08:42 PM
How do I get my worksheets to print in the right order? Wilde Excel Worksheet Functions 5 November 8th 05 12:07 PM
Worksheets in alphabetical order Mark Excel Programming 3 November 28th 03 10:24 AM


All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"