This is an example of sorting functions that allow alphabetical or numerical sorting by a specified column. The functions below put empty values to the end while sorting.
Here is a VBA code for alphabetical and numerical sorting functions:
'-------------------------------------------------------------------------
' Source: risksir.com
' Description: Numerical sorting by selected column
'-------------------------------------------------------------------------
Function Sort123(SourceRange As Variant, ByVal n As Integer) As Variant
' Sorting an array of NUMBERS by N-th column, sending empty strings to the end
SourceArr = SourceRange
If n > UBound(SourceArr, 2) Or n < LBound(SourceArr, 2) Then MsgBox "There's no " & n & " column in the array!", vbCritical: Exit Function
Dim Check As Boolean, iCount As Integer, jCount As Integer, nCount As Integer
ReDim tmpArr(UBound(SourceArr, 2)) As Variant
Do Until Check
Check = True
For iCount = LBound(SourceArr, 1) To UBound(SourceArr, 1) - 1
If ((SourceArr(iCount, n) > SourceArr(iCount + 1, n) Or CStr(SourceArr(iCount, n)) = "") And CStr(SourceArr(iCount + 1, n)) <> "") Then
For jCount = LBound(SourceArr, 2) To UBound(SourceArr, 2)
tmpArr(jCount) = SourceArr(iCount, jCount)
If SourceArr(iCount, jCount) = "" Then tmpArr(jCount) = ""
SourceArr(iCount, jCount) = SourceArr(iCount + 1, jCount)
SourceArr(iCount + 1, jCount) = tmpArr(jCount)
Check = False
Next
End If
Next
Loop
Sort123 = SourceArr
End Function
'-------------------------------------------------------------------------
' Source: risksir.com
' Description: Alphabetical sorting by selected column
'-------------------------------------------------------------------------
Function SortABC(SourceRange As Variant, ByVal n As Integer) As Variant
' Sorting an array of SRTINGS by N-th column, sending empty strings to the end
SourceArr = SourceRange
If n > UBound(SourceArr, 2) Or n < LBound(SourceArr, 2) Then MsgBox "There's no " & n & " column in the array!", vbCritical: Exit Function
Dim Check As Boolean, iCount As Integer, jCount As Integer, nCount As Integer
ReDim tmpArr(UBound(SourceArr, 2)) As Variant
Do Until Check
Check = True
For iCount = LBound(SourceArr, 1) To UBound(SourceArr, 1) - 1
If ((UCase(CStr(SourceArr(iCount, n))) > UCase(CStr(SourceArr(iCount + 1, n))) Or CStr(SourceArr(iCount, n)) = "") And CStr(SourceArr(iCount + 1, n)) <> "") Then
For jCount = LBound(SourceArr, 2) To UBound(SourceArr, 2)
tmpArr(jCount) = SourceArr(iCount, jCount)
If SourceArr(iCount, jCount) = "" Then tmpArr(jCount) = ""
SourceArr(iCount, jCount) = SourceArr(iCount + 1, jCount)
SourceArr(iCount + 1, jCount) = tmpArr(jCount)
Check = False
Next
End If
Next
Loop
SortABC = SourceArr
End Function