Sort excel sheets based on dates.

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi everyone,

Can we sort the excel worksheets based on the dates.

like example,

One of my workbook contains more than 50 worksheets,and each worksheets would be named like "31-01-1990_GHUJJIUK","29-05-2019_kdsajasjads" and so on . Where in beginning of each worksheets date would be provided based on that can we arrange our sheets.

I am trying to arrange the sheets from today to the oldest one at last

Regards,
Dhruva
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Code:
Sub SortSheets()
Dim sh%, i%, j%, x As Date, y As Date
sh = Sheets.Count
Application.ScreenUpdating = False
On Error Resume Next
For i = 1 To sh - 1
    x = DateValue(Left(Sheets(i).Name, 10))
    For j = i + 1 To sh
        y = DateValue(Left(Sheets(j).Name, 10))
        If y > x Then Sheets(j).Move before:=Sheets(i)
    Next j
Next i
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top