ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How do I sort worksheets in excel? i.e. Order them by date (https://www.excelbanter.com/excel-worksheet-functions/40882-how-do-i-sort-worksheets-excel-i-e-order-them-date.html)

Nick

How do I sort worksheets in excel? i.e. Order them by date
 
How do I sort worksheets in excel? i.e. if i had multiple worksheets in a
workbook each containing a date, how could i sort the worksheets into date
order?

Gary L Brown

'/=================================================/
Sub WkshtSort_Ascending()
Dim i As Integer, x As Integer
Dim iWksheetCount As Integer

iWksheetCount = Application.ActiveWorkbook.Worksheets.Count

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

End Sub
'/=================================================/
Sub WkshtSort_Descending()
Dim i As Integer, x As Integer
Dim iWksheetCount As Integer

iWksheetCount = Application.ActiveWorkbook.Worksheets.Count

For i = 1 To iWksheetCount
For x = i To iWksheetCount
If UCase(Worksheets(x).Name) _
UCase(Worksheets(i).Name) Then
Worksheets(x).Move Befo=Worksheets(i)
End If
Next x
Next i

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

HTH,
--
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"Nick" wrote:

How do I sort worksheets in excel? i.e. if i had multiple worksheets in a
workbook each containing a date, how could i sort the worksheets into date
order?



All times are GMT +1. The time now is 01:02 AM.

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