VBA to sort Sheets in descending order

noslenwerd

Board Regular
Joined
Nov 12, 2019
Messages
77
Office Version
  1. 365
Wondering if there is some VBA code that may look at sheets 2 through (sheet count), and sort them in descending order as shown?

I have a process that compares data between each sheet, and they must be in proper order. I do not trust the users to make sure these sheets are sorted correctly :)
Thanks!

Below is an example of the format in my workbook.
1618867241504.png
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,148
Office Version
  1. 2010
Platform
  1. Windows
According to post #9 :​
VBA Code:
Sub Demo2()
              Dim S$(), V(), N&, A$
    With Sheets
        If .Count > 2 Then
            ReDim S(1 To .Count - 1)
            ReDim V(1 To .Count - 1)
        For N = 2 To .Count
            With .Item(N)
                S(N - 1) = .Name
                V(N - 1) = CLng(DateSerial(2000 + Right(.Name, 2), Left(.Name, 2), Mid(.Name, 3, 2)))
            End With
        Next
            V = Application.Match(Application.Large(V, Evaluate("COLUMN(" & [A1].Resize(, .Count - 1).Address & ")")), V, 0)
            A = ActiveSheet.Name
        For N = 1 To .Count - 2
            If .Item(N + 1).Name <> S(V(N)) Then .Item(S(V(N))).Move .Item(N + 1)
        Next
            Sheets(A).Select
        End If
    End With
End Sub
 
Solution

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,148
Office Version
  1. 2010
Platform
  1. Windows
In my previous code it's more obvious to use .Item(A).Select rather than Sheets(A).Select(The same for post #5)
 

Forum statistics

Threads
1,137,154
Messages
5,679,913
Members
419,862
Latest member
Bluewings666

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
Top