' insert sort Public Sub InsertSort(ByRef A() As Variant, ByVal Lb As Long, ByVal Ub As Long) Dim t As Variant Dim i As Long Dim j As Long ' sort A[Lb..Ub] For i = Lb + 1 To Ub t = A(i) ' shift elements down until insertion point found For j = i - 1 To Lb Step -1 If A(j) <= t Then Exit For A(j + 1) = A(j) Next j ' insert A(j + 1) = t Next i End Sub