Sub Main()
Dim c As Range, r As Range, aryAA()
With Sheets(1)
For Each c In .[A1:B10]
c.Value = c.Address
Next c
.[a2] = "" 'Add a blank cell.
.[A3] = 3 'Add some numbers.
.[A4] = 2
Set r = .Range("A2:B" & .Cells(Rows.Count, "A").End(xlUp).Row)
End With
aryAA = advArrayListSort(r, False) 'No sort.
MsgBox Join(aryAA, vbLf)
'Sort descending. Text is the 2nd in this case.
aryAA = advArrayListSort(r, , , False)
MsgBox Join(aryAA, vbLf)
End Sub
'https://msdn.microsoft.com/en-us/library/system.collections.arraylist(v=vs.110).aspx
Function advArrayListSort(sn As Variant, _
Optional tfSort As Boolean = True, _
Optional tfAscending1 As Boolean = True, _
Optional tfAscending2 As Boolean = True, _
Optional tfNumbersFirst As Boolean = True, _
Optional tfDelBlanks As Boolean = True) As Variant
Dim i As Long, c1 As Object, c2 As Object
Dim a1() As Variant, a2() As Variant, a() As Variant
Dim v As Variant
Set c1 = CreateObject("System.Collections.ArrayList")
Set c2 = CreateObject("System.Collections.ArrayList")
For Each v In sn
If IsNumeric(v) = True Then
c1.Add v
ElseIf tfDelBlanks And v <> "" Then c2.Add v
ElseIf tfDelBlanks = False Then c2.Add v
End If
Next v
On Error Resume Next 'If no number or text, errors would occur.
If tfSort Then
c1.Sort 'Sort ascendending
c2.Sort 'Sort ascending
If tfAscending1 = False Then c1.Reverse 'Sort and then Reverse to sort descending
If tfAscending2 = False Then c2.Reverse 'Sort and then Reverse to sort descending
End If
a1() = c1.Toarray()
a2() = c2.Toarray()
If tfNumbersFirst = True Then
a() = a1()
For i = 1 To c2.Count
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = a2(i - 1)
Next i
Else
a() = a2()
For i = 1 To c1.Count
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = a1(i - 1)
Next i
End If
advArrayListSort = a()
End Function