Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort combobox results in userform

Status
Not open for further replies.

MrMode

Technical User
Aug 28, 2003
195
GB
I have created a user form that has combo boxes which use an advanced filter to populate list boxes.

The unique / distinct results are returned in the order in which they appear in the list, I would like to sort them desc but have no idea how to?!

Code:
Private Sub TestPopulatecmbCategory()
    Dim v, e
    With Sheets("DATA").Range("A2:A39")
        v = .Value
    End With
    With CreateObject("scripting.dictionary")
        .comparemode = 1
        For Each e In v
            If Not .exists(e) Then .Add e, Nothing
        Next
        If .Count Then Me.cmbCategory.List = Application.Transpose(.keys)
    End With
    
     
End Sub

Any and all help most appreciated
 
Or you could just sort the source range. So something like:

Code:
[blue]Private Sub TestPopulatecmbCategory()
    Dim myRange As Range
    
    Set myRange = Sheets("DATA").Range("A2:A39")
        
    With Sheets("DATA").Sort
        .SortFields.Clear
        .SortFields.Add myRange, xlSortOnValues, xlDescending
        .SetRange myRange
        .Apply
    End With
    
    Me.cmbCategory.List = myRange.Value
End Sub[/blue]

 
Thank you both. Interesting ways to approach the issue I will work on both.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top