+ Reply to Thread
Results 1 to 7 of 7

Sorting within an array, or in a combobox

Hybrid View

JP Romano Sorting within an array, or... 05-27-2011, 05:08 PM
jaslake Re: Sorting within an array,... 05-27-2011, 05:29 PM
Krishnakumar Re: Sorting within an array,... 05-28-2011, 04:33 AM
JP Romano Re: Sorting within an array,... 05-31-2011, 09:25 AM
snb Re: Sorting within an array,... 05-31-2011, 09:38 AM
JP Romano Re: Sorting within an array,... 05-31-2011, 12:45 PM
shg Re: Sorting within an array,... 05-31-2011, 01:06 PM
  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Sorting within an array, or in a combobox

    SNB, as I'm being asked to do more and more with Excel/VBA here at work, I try to find better, faster, smarter ways of doing things with each effort. With this little project, I wanted to force myself to use arrays, which are very new and interesting to me. My interest wasn't only in the end point, but different ways to get there. Hope that makes sense, and as always, thanks for taking the time to read and offer something incredible!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Sorting within an array, or in a combobox

    One more alternative:
    Sub demo()
        Sheet1.ComboBox1.List = Range("A2:A11").Value
        SortTheBox Sheet1.ComboBox1
        
        Sheet1.ListBox1.List = Range("B2:B11").Value
        SortTheBox Sheet1.ListBox1
    End Sub
    
    Function SortTheBox(vCtl As Variant) As Boolean
        Dim i         As Long
        Dim j         As Long
    
        If Not IsObject(vCtl) Then Exit Function
    
        Select Case TypeName(vCtl)
            Case "ComboBox", "ListBox"
                With vCtl
                    For i = 1 To .ListCount - 1
                        For j = 0 To i - 1
                            If .List(i) < .List(j) Then
                                .AddItem .List(i), j
                                .RemoveItem i + 1
                                Exit For
                            End If
                        Next j
                    Next i
                End With
    
                SortTheBox = True
        End Select
    End Function
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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