With comment


    Public Sub Array_BubbleSort(ByRef arr() As Variant)
     ' sorts an array using bubblesort, returning the sorted array
     Dim n As Long, newn As Variant, i As Long, tmp As Variant
     n = UBound(arr)
     Do
        newn = 1
        For i = 0 To n - 1
           If arr(i) > arr(i+1) Then
              'swap
              tmp = arr(i+1)
              arr(i+1) = arr(i)
              arr(i) = tmp
              newn = i+1
           End If
        Next
        n = newn
     Loop While (n > 1)

  End Sub
  

Without comment


    Public Sub Array_BubbleSort(ByRef arr() As Variant)
     Dim n As Long, newn As Variant, i As Long, tmp As Variant
     n = UBound(arr)
     Do
        newn = 1
        For i = 0 To n - 1
           If arr(i) > arr(i+1) Then
              tmp = arr(i+1)
              arr(i+1) = arr(i)
              arr(i) = tmp
              newn = i+1
           End If
        Next
        n = newn
     Loop While (n > 1)

  End Sub