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

Home
VBA / Excel / Access / Word
1.Access
2.Application
3.Data Type
4.Data Type Functions
5.Date Functions
6.Excel
7.File Path
8.Forms
9.Language Basics
10.Math Functions
11.Outlook
12.PowerPoint
13.String Functions
14.Windows API
15.Word
16.XML
VBA / Excel / Access / Word » Data Type » Array Sort 
using dynamic arrays in bubble sort
 
Public Sub DynamicBubble()
    Dim tempVar As Integer
    Dim anotherIteration As Boolean
    Dim 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 = To arraySize
        myArray(I - 1= Cells(I, "A").Value
    Next I
    Do
        anotherIteration = False
        For I = To arraySize - 2
            If myArray(I> myArray(I + 1Then
                tempVar = myArray(I)
                myArray(I= myArray(I + 1)
                myArray(I + 1= tempVar
                anotherIteration = True
            End If
        Next I
    Loop While anotherIteration = True
    '
    For I = 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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.