Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion sorting worksheets
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David McRitchie  
View profile  
 More options Jun 15 1999, 3:00 am
Newsgroups: microsoft.public.excel.misc
From: dmcritc...@aol.com (David McRitchie)
Date: 1999/06/15
Subject: Re: sorting worksheets
Hi Graham,             (posted with email copy)
Here are some macros of interest.  I prefer to use Jeff Webb's example for
sorting which sorts sheets within their sheet type.  Particularly useful in
XL95 where modules are seen on the sheet tabs.

I had been perplexed into thinking John Manville's  SortSheets did the same but
what I had not seen was that it sorted worksheets only leaving the others in
place as they were.  The modified SortALLSheetes will sort all sheets
alphabetically regardless of type.

EnumerateSheets will create a list of sheets and their type in the order you
have them in your workbook.

For those who have never installed  a macro see orange shaded area in
  http://members.aol.com/dmcritchie/excel/formula.htm  
If line turns to RED it denotes syntax error and probably belongs to line
above.      

'EnumerateSheets - list of sheets from active cell down, uses two columns
'For reordering sheets, I prefer Jeff Web's "ReOrderSheets"

'ReOrderSheets - reorders sheets within Type
'      Types: Worksheet, Chart, Module, Dialogsheet
'SortSheets - reorders only Worksheets
'SortALLSheets - reorders ALL sheets, regardless of type

Sub EnumerateSheets()
  'listed from active cell down 2-cols --  DMcRitchie 1999-03-04
  Application.Calculation = xlManual   'xl97 up use xlCalculationManual  
  Application.ScreenUpdating = False
  cRow = ActiveCell.Row
  cCol = ActiveCell.Column
  For csht = 1 To ActiveWorkbook.Sheets.Count  'worksheet or sheets
     cells(cRow - 1 + csht, cCol) = Sheets(csht).Name
     cells(cRow - 1 + csht, cCol + 1) = TypeName(Sheets(csht))
  Next csht
  Application.ScreenUpdating = True
  Application.Calculation = xlAutomatic   'xl97 up use xlCalculationAutomatic
End Sub

Sub ReOrderSheets()
  ' page 48 in  "Using Excel VBA" Jeff Webb
  'for each sheet in a workbook ...
  For Each shtcount In Sheets
     'group the different types of sheets together
     Select Case TypeName(shtcount)
        Case "Worksheet"
           iWrk = iWrk + 1
           shtcount.Move After:=Sheets(iWrk)
        Case "Chart"
           iChrt = iChrt + 1
           shtcount.Move After:=Sheets(Worksheets.Count + iChrt)
        Case "Module"
           imod = imod + 1
           shtcount.Move After:=Sheets(Worksheets.Count + Charts.Count + imod)
        Case "DialogSheet"
           iDlg = iDlg + 1
           shtcount.Move After:=Sheets(Worksheets.Count + Charts.Count +
Modules.Count + iDlg)
     End Select
  Next shtcount
End Sub

Sub SortSheets()
  'sort worksheets within a workbook in Excel 7 -- Bill Manville
    Dim iSheet As Integer, iBefore As Integer
    MsgBox ActiveWorkbook.Worksheets.Count
  For iSheet = 1 To ActiveWorkbook.Worksheets.Count
    Worksheets(iSheet).Visible = True
    For iBefore = 1 To iSheet - 1
      If UCase(Worksheets(iBefore).Name) > UCase(Worksheets(iSheet).Name) Then
        ActiveWorkbook.Worksheets(iSheet).Move
Before:=ActiveWorkbook.Worksheets(iBefore)
        Exit For
      End If
    Next iBefore
  Next iSheet
End Sub

Sub SortALLSheets()
  'sort sheets within a workbook in Excel 7 -- Bill Manville
  'modified to sort all sheets instead of just worksheets
    Dim iSheet As Integer, iBefore As Integer
    MsgBox ActiveWorkbook.Sheets.Count
  For iSheet = 1 To ActiveWorkbook.Sheets.Count
    Sheets(iSheet).Visible = True
    For iBefore = 1 To iSheet - 1
      If UCase(Sheets(iBefore).Name) > UCase(Sheets(iSheet).Name) Then
        ActiveWorkbook.Sheets(iSheet).Move
Before:=ActiveWorkbook.Sheets(iBefore)
        Exit For
      End If
    Next iBefore
  Next iSheet
End Sub

HTH,
David McRitchie
My Excel Pages:  http://members.aol.com/dmcritchie/excel/excel.htm

>From: The Sgiliau Team <sgil...@harlech.ac.uk>   Graham  15Jun1999
>I know how to manually sort worksheets, but can the process be automated?
>I need them in alphabetical order.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.