Assuming header in A1 and sort from A2 onwards.
Sub test()
Dim a, i As Long, ii As Long, iii As Long, temp
With Range("a1", Range("a" & Rows.Count).End(xlUp))
a = .Value
ReDim Preserve a(1 To UBound(a, 1), 1 To 2)
For i = 2 To UBound(a, 1)
a(i, UBound(a, 2)) = GetSortVal(a(i, 1))
Next
For i = 2 To UBound(a, 1) - 1
For ii = i + 1 To UBound(a, 1)
If a(i, UBound(a, 2)) > a(ii, UBound(a, 2)) Then
For iii = 1 To UBound(a, 2)
temp = a(i, iii): a(i, iii) = a(ii, iii): a(ii, iii) = temp
Next
End If
Next
Next
.Value = a
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+"
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(4, "0")))
Next
End If
End With
GetSortVal = txt
End Function
Bookmarks