using dynamic arrays in bubble sort : Array Sort « Data Type « VBA / Excel / Access / Word






using dynamic arrays in bubble sort

 
Public Sub DynamicBubble()
    Dim tempVar As Integer
    Dim anotherIteration As Boolean
    Dim I As Integer
    Dim arraySize As Integer
    Dim myArray() As Integer
    Do
        arraySize = I
        I = I + 1
    Loop Until Cells(I, "A").Value = ""
    ReDim myArray(arraySize - 1)
    For I = 1 To arraySize
        myArray(I - 1) = Cells(I, "A").Value
    Next I
    Do
        anotherIteration = False
        For I = 0 To arraySize - 2
            If myArray(I) > myArray(I + 1) Then
                tempVar = myArray(I)
                myArray(I) = myArray(I + 1)
                myArray(I + 1) = tempVar
                anotherIteration = True
            End If
        Next I
    Loop While anotherIteration = True
    '
    For I = 1 To arraySize
        Cells(I, "B").Value = myArray(I - 1)
    Next I
End Sub

 








Related examples in the same category

1.VBA Bubble Sort
2.Performing a Binary Search through an Array
3.Quick sort
4.Quick Sort 2