Results 1 to 8 of 8

Sort an Array of items by Alpha

Threaded View

realniceguy5000 Sort an Array of items by... 07-05-2011, 11:00 AM
snb Re: Sort an Array of items by... 07-05-2011, 11:13 AM
Domski Re: Sort an Array of items by... 07-05-2011, 11:14 AM
snb Re: Sort an Array of items by... 07-05-2011, 11:46 AM
realniceguy5000 Re: Sort an Array of items by... 07-05-2011, 01:06 PM
snb Re: Sort an Array of items by... 07-05-2011, 04:08 PM
  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Sort an Array of items by Alpha

    Hi,

    I have the following script that collects my data into an array and adds to a combo-box, However the data is unsorted. I found a script that is suppose to sort the array, However I'm not having any luck with it. it may be the way I am calling it or something else I cant see at the moment.

    I'm looking to either sort the array then add the items to the combo-box or Just sort the items that are placed in the combo-box. Or maybe someone has another Idea...

    Can someone please take a look and advise.

    Thanks as always, Mike

    Private Sub UserForm_Initialize()
    Dim startrow As Long
    Dim lastrow As Long
    Dim myArray()
    Dim a As Long
    Dim i As Long
    Dim myRowValue As String
    Dim myColumn As Long
    Dim Temp As Variant, X As Integer
    myColumn = 249
    startrow = 4
    lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
    For i = startrow To lastrow
    myRowValue = Cells(i, myColumn).Value
        If myRowValue = "0" Or myRowValue = vbNullString Then
        Else
            ReDim Preserve myArray(a)
            myArray(a) = myRowValue
            a = a + 1
        End If
    Next
    For N = LBound(myArray) To UBound(myArray)
    ComboBox4.AddItem myArray(N)
    Next
    Stop
    SortArray (myArray)
     
    End Sub
    The Sort Script...

    Public Function SortArray(ByRef TheArray As Variant)
    Sorted = False
    Do While Not Sorted
        Sorted = True
    For X = 0 To UBound(TheArray) - 1
        If TheArray(X) > TheArray(X + 1) Then
            Temp = TheArray(X + 1)
            TheArray(X + 1) = TheArray(X)
            TheArray(X) = Temp
            Sorted = False
        End If
    Next X
    Loop
    End Function
    Last edited by realniceguy5000; 07-05-2011 at 01:07 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1