Originally Posted by
JEAN1972
Hi Jindon
Some examples numeric ones first AND alphabetical last like 01_15__sodium peroxide ,beoh_10a27,alphabetical,reports 2015_a_01IE.
See if this is how you wanted.
Sub test()
Dim ws As Worksheet, i As Long
With CreateObject("System.Collections.SortedList")
For Each ws In Sheets
.Item(GetSortVal(ws.Name)) = ws.Name
Next
For i = .Count - 1 To 0 Step -1
Sheets(.GetByIndex(i)).Move before:=Sheets(1)
Next
End With
End Sub
Function GetSortVal(ByVal txt As String) As String
Dim i As Long, m As Object
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\d+(\.\d+)?"
If .test(txt) Then
For i = .Execute(txt).Count - 1 To 0 Step -1
Set m = .Execute(txt)(i)
txt = Application.Replace(txt, m.firstindex + 1, m.Length, _
Format$(m.Value, String(12, "0") & "," & String(10, "0")))
Next
End If
End With
GetSortVal = txt
End Function
Bookmarks