Avatar of Gavin Tech
Gavin TechFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

excel 2007 - how do I sort workspaces in alphabetical order

I have an excel spreadsheet with lots of different workspaces for differing topic but there are a lot of workspaces now and not in alphabetical order. How can this be done automatically.
Microsoft Excel

Avatar of undefined
Last Comment
Jacques Geday
Avatar of dlmille
dlmille
Flag of United States of America image

Please upload an example workbook, so the experts can more readily assist.  Ensure its non-sensitive data, obfuscate the data if you need to.  There should be a framework from which to develop a solution, as your question is too broad.

Cheers,

Dave
Avatar of Gavin Tech
Gavin Tech
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

User generated image
I think iv over confused things. All I need are the sheets at the bottom of the page in alphabetical order. The picture above is in the order sheet1,sheet2 and Asheet3 which should be first. Hope that clears things up
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

Try this code depending on how you reply Yes will sort ascending no will sort descending all sheets in the workbook based on hte sheet name.
rgds/gowflow
Sub Sort_Active_Book()
Dim I As Integer
Dim J As Integer
Dim iAnswer As VbMsgBoxResult
'
' Prompt the user as which direction they wish to
' sort the worksheets.
'
   iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
     & "Clicking No will sort in Descending Order", _
     vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
   For I = 1 To Sheets.count
      For J = 1 To Sheets.count - 1
'
' If the answer is Yes, then sort in ascending order.
'
         If iAnswer = vbYes Then
            If UCase$(Sheets(J).Name) > UCase$(Sheets(J + 1).Name) Then
               Sheets(J).Move After:=Sheets(J + 1)
            End If
'
' If the answer is No, then sort in descending order.
'
         ElseIf iAnswer = vbNo Then
            If UCase$(Sheets(J).Name) < UCase$(Sheets(J + 1).Name) Then
               Sheets(J).Move After:=Sheets(J + 1)
            End If
         End If
      Next J
   Next I
End Sub

Open in new window

Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

For your easy refrence here is a workbook with the button in sheet1 and the code above that give you an example on how to implement in your workbook.
gowflow
Sort-Sheets.xls
Avatar of Gavin Tech
Gavin Tech
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Sorry but im confused as to how to use this code on my spreadsheet? Please advise.
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

ok fine
Are you using Excel 2007 or Excel 2003 ? as it is diffrent for each
gowflow
Avatar of Gavin Tech
Gavin Tech
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

excel 2007
ASKER CERTIFIED SOLUTION
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo